private void CheckForCollisions() { if (Player1.IsSelfIntersecting()) // Check for collisions with itself { SetGameOver("Hit itself"); // If so, trigger the game-over screen } if (Player1.IsIntersectingRect(new Rectangle(-100, 0, 100, GameCanvas.Height))) { SetGameOver("Hit left wall"); } if (Player1.IsIntersectingRect(new Rectangle(0, -100, GameCanvas.Width, 100))) { SetGameOver("Hit top wall"); } if (Player1.IsIntersectingRect(new Rectangle(GameCanvas.Width, 0, 100, GameCanvas.Height))) { SetGameOver("Hit right wall"); } if (Player1.IsIntersectingRect(new Rectangle(0, GameCanvas.Height, GameCanvas.Width, 100))) { SetGameOver("Hit bottom wall"); } // Is hitting food var snakeRects = Player1.GetRects(); foreach (var rect in snakeRects) { if (FoodMngr.IsIntersectingRect(rect, true)) { FoodMngr.AddRandomFood(); Player1.AddBodySegments(1); Player1.AddScore(); score++; ScoreTxtBox.Text = score.ToString(); } } }