FlyingBird.PipeManager.Intersects C# (CSharp) Method

Intersects() public method

A value indicating whether the player intersects.
public Intersects ( Player player ) : bool
player Player The Player.
return bool
        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;
        }

Usage Example

Exemplo n.º 1
0
 /// <summary>
 ///     Updates the collision.
 /// </summary>
 private void UpdateCollision()
 {
     if (!_isDead)
     {
         if (_pipeManager.Intersects(_player))
         {
             _isDead = true;
             _die.Play();
         }
     }
 }