Exemplo n.º 1
0
        /// <summary>
        ///     A value indicating whether the player intersects.
        /// </summary>
        /// <param name="player">The Player.</param>
        /// <returns>True if intersecting.</returns>
        public bool Intersects(Player player)
        {
            lock (_lockObj)
            {
                foreach (Pipe pipe in _pipes)
                {
                    /*/var polygon1 = new Polygon();
                    polygon1.Add(new Vector2(pipe.Position.X, pipe.Position.Y),
                        new Vector2(pipe.Position.X + 44, pipe.Position.Y),
                        new Vector2(pipe.Position.X + 44, pipe.Position.Y + pipe.TopPipeHeight + 22),
                        new Vector2(pipe.Position.X, pipe.Position.Y + pipe.TopPipeHeight + 22));

                    var polygon2 = new Polygon();
                    polygon2.Add(new Vector2(pipe.Position.X, 480), new Vector2(pipe.Position.X + 44, 480),
                      new Vector2(pipe.Position.X + 44, pipe.BottomPipeY - 22),
                                   new Vector2(pipe.Position.X, pipe.BottomPipeY - 22));

                    if (player.Bounds.Intersects(polygon1))
                    {
                        return true;
                    }

                    if (player.Bounds.Intersects(polygon2))
                    {
                        return true;
                    }/*/

                    var rect1 = new Rectangle(pipe.Position.X, pipe.Position.Y, 46, pipe.TopPipeHeight + 22);
                    var rect2 = new Rectangle(pipe.Position.X, pipe.BottomPipeY, 46, pipe.BottomPipeHeight);
                    var playerrect = new Rectangle(player.Position, new Vector2(32, 24));

                    if (playerrect.Intersects(rect1) || playerrect.Intersects(rect2))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Loads the content.
        /// </summary>
        public override void OnLoadContent()
        {
            _animatedBackground = new AnimatedBackground(Content.Load<Texture2D>("background.png"));
            _instructions = new Instructions(Content.Load<Texture2D>("instructions.png")) {Visible = true};
            _player = new Player(Content.Load<Texture2D>("bird_sprite.png"), Content.Load<Texture2D>("bird_erased.png"));
            _receivedCoin = new SoundEffect(Content.Load<Sound>("score.wav")) { Volume = 0.2f };
            _die = new SoundEffect(Content.Load<Sound>("dead.wav")) { Volume = 0.2f };
            _scoreboard = new Scoreboard();
            _pipeManager = new PipeManager(Content.Load<Texture2D>("pipe_body.png"),
                Content.Load<Texture2D>("pipe_bottom.png"), Content.Load<Texture2D>("pipe_top.png"));
            _swing = new SoundEffect(Content.Load<Sound>("swing.wav")){Volume = 0.2f};
            _pipeManager.ScoreChanged += _pipeManager_ScoreChanged;
            _font = new Font("Segoe UI", 9, TypefaceStyle.Regular);
            _deviceHintPosition = new Vector2(0, 0);

            int x = Convert.ToInt32(_resolution.Split('x')[0]);
            int y = Convert.ToInt32(_resolution.Split('x')[1]);

            SGL.Components.Get<RenderTarget>().Window.Size = new Vector2(x, y);
            SGL.Components.Get<GraphicsDevice>().BackBuffer.Scaling = true;
        }