コード例 #1
0
ファイル: Viewport.cs プロジェクト: fiahil/Kaboom
        /// <summary>
        /// Adjust the delta of the drag if the focus is out of range
        /// </summary>
        /// <param name="map">the map object of the game</param>
        /// <param name="deltaX">delta of the move on X axe</param>
        /// <param name="deltaY">delta of the move on Y axe</param>
        public void AdjustPos(Map map, ref int deltaX, ref int deltaY)
        {
            if (!IsZoomed)
            {
                return;
            }
            var vision = new Rectangle(80, 80, graphicsDevice_.Viewport.Width - 160, graphicsDevice_.Viewport.Height - 160);

            if (deltaY > 0)
            {
                // Top pas dans le square ok
                if (map.LineIsContainHorizontaly(vision, 0))
                    deltaY = 0;
            }
            else
            {
                // Bot pas dans le square
                if (map.LineIsContainHorizontaly(vision, map.SizeY - 1))
                    deltaY = 0;
            }

            if (deltaX > 0)
            {
                // Left pas dans le square ok
                if (map.LineIsContainVerticaly(vision, 0))
                    deltaX = 0;
            }
            else
            {
                // Right pas dans le square
                if (map.LineIsContainVerticaly(vision, map.SizeX - 1))
                    deltaX = 0;
            }
        }
コード例 #2
0
ファイル: MainGame.cs プロジェクト: fiahil/Kaboom
        /// <summary>
        /// Initialise game
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.hud_ = new Hud(this, this.spriteBatch_);
            hud_.GameInfos.Round = 10;
            score_.Restart(10);

            this.map_ = new Map(this, this.spriteBatch_, KaboomResources.Level);
            this.ladder_.AddEntry(KaboomResources.Level.Score.Score1, "King");
            this.ladder_.AddEntry(KaboomResources.Level.Score.Score2, "Prince");
            this.ladder_.AddEntry(KaboomResources.Level.Score.Score3, "Champion");
            this.hud_.GameInfos.Round = KaboomResources.Level.Score.Turn;
            this.map_.EndGameManager += ManageEndGame;
            Viewport.Instance.Initialize(GraphicsDevice, this.map_);

            this.Components.Add(this.map_);
            this.Components.Add(this.hud_);

            MediaPlayer.Play(KaboomResources.Musics["InGame"]);
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume = 0.5f;
        }
コード例 #3
0
ファイル: Viewport.cs プロジェクト: fiahil/Kaboom
        /// <summary>
        /// Initialize Viewport instance
        /// </summary>
        /// <param name="graphicsDevice">Graphic device used to fetch Viewport</param>
        /// <param name="map">Map</param>
        public void Initialize(GraphicsDevice graphicsDevice, Map map)
        {
            this.graphicsDevice_ = graphicsDevice;
            this.maxZoom_ = new int[2];

            this.map_ = map;
            this.oldOrientation_ = this.GetOrientation();
            this.PinchPos = new Point(this.map_.SizeX / 2, this.map_.SizeY / 2);

            if (this.GetOrientation() == DisplayOrientation.Portrait)
            {
                maxZoom_[1] = this.graphicsDevice_.Viewport.Width / this.map_.SizeX;
                if (maxZoom_[1] >
                    (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Height)) / this.map_.SizeY)
                    maxZoom_[1] = (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Width)) /
                                  this.map_.SizeY;
                maxZoom_[0] = this.graphicsDevice_.Viewport.Height / this.map_.SizeX;
                if (maxZoom_[0] >
                    (this.graphicsDevice_.Viewport.Width - (int) (0.15 * this.graphicsDevice_.Viewport.Height)) / this.map_.SizeY)
                    maxZoom_[0] = (this.graphicsDevice_.Viewport.Width - (int) (0.15 * this.graphicsDevice_.Viewport.Width)) /
                                  this.map_.SizeY;
                Camera.Instance.DimY = maxZoom_[1];
                Camera.Instance.DimX = maxZoom_[1];
                Camera.Instance.OffX = (this.graphicsDevice_.Viewport.Width - (maxZoom_[1] * this.map_.SizeX)) / 2;
                Camera.Instance.OffY = (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Width) -
                                        (maxZoom_[1] * this.map_.SizeY)) / 2 + (int) (0.15 * this.graphicsDevice_.Viewport.Width);
            }
            else
            {
                maxZoom_[0] = this.graphicsDevice_.Viewport.Width / this.map_.SizeX;
                if (maxZoom_[0] >
                    (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Height)) / this.map_.SizeY)
                    maxZoom_[0] = (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Height)) /
                                  this.map_.SizeY;
                maxZoom_[1] = this.graphicsDevice_.Viewport.Height / this.map_.SizeX;
                if (maxZoom_[1] >
                    (this.graphicsDevice_.Viewport.Width - (int) (0.15 * this.graphicsDevice_.Viewport.Width)) / this.map_.SizeY)
                    maxZoom_[1] = (this.graphicsDevice_.Viewport.Width - (int) (0.15 * this.graphicsDevice_.Viewport.Height)) /
                                  this.map_.SizeY;
                Camera.Instance.DimY = maxZoom_[0];
                Camera.Instance.DimX = maxZoom_[0];
                Camera.Instance.OffX = (this.graphicsDevice_.Viewport.Width - (maxZoom_[0] * this.map_.SizeX)) / 2;
                Camera.Instance.OffY = (this.graphicsDevice_.Viewport.Height - (int) (0.15 * this.graphicsDevice_.Viewport.Height) -
                                        (maxZoom_[0] * this.map_.SizeY)) / 2 + (int) (0.15 * this.graphicsDevice_.Viewport.Height);
            }
        }