/// <summary> /// Draws the food pellets /// </summary> /// <param name="Canvas">Canvas object (game screen) to draw on</param> public void Draw(Graphics Canvas) { // Iterate over all food pellets and draw them Brush SnakeColor = Brushes.DarkBlue; foreach (FoodPellet Pellet in m_FoodPellets) { Point PartPos = Pellet.GetPosition(); Canvas.FillEllipse(SnakeColor, new Rectangle(PartPos.X + (m_CircleRadius / 4), PartPos.Y + (m_CircleRadius / 4), m_CircleRadius / 2, m_CircleRadius / 2)); } }
// 畫圖時間 public void Draw(Graphics Canvas) { // 跑一遍食物然後畫畫 Brush SnakeColor = Brushes.BlueViolet; foreach (FoodPellet Pellet in m_FoodPellets) { Point PartPos = Pellet.GetPosition(); Canvas.FillEllipse(SnakeColor, new Rectangle(PartPos.X + (m_CircleRadius / 4), PartPos.Y + (m_CircleRadius / 4), m_CircleRadius / 2, m_CircleRadius / 2)); } }
public bool IsIntersectingRectWithRed(Rectangle rect, bool RemoveFood) { foreach (FoodPelletRed Pellet in m_FoodPelletsRed) { Point PartPos = Pellet.GetPosition(); if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius))) { if (RemoveFood) { m_FoodPelletsRed.Remove(Pellet); } return(true); } } return(false); }
/// <summary> /// Determines whether the given rectangle intersects with any existing food pellets /// </summary> /// <param name="rect">The rectangle to check for collision with food pellets</param> /// <param name="RemoveFood">Whether to remove the food pellets intersecting with the rectangle</param> /// <returns>Whether there was an intersection</returns> public bool IsIntersectingRect(Rectangle rect, bool RemoveFood) { foreach (FoodPellet Pellet in m_FoodPellets) // Check each food pellet { Point PartPos = Pellet.GetPosition(); // Check rectangle intersection with food pellet if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius))) { if (RemoveFood) // Remove food pellet if RemoveFood parameter is true { m_FoodPellets.Remove(Pellet); } return(true); } } return(false); }
// 吃到食物偵測器 public bool IsIntersectingRect(Rectangle rect, bool RemoveFood) { foreach (FoodPellet Pellet in m_FoodPellets) // 跑一遍食物陣列 { Point PartPos = Pellet.GetPosition(); // 檢查是否碰到食物 if (rect.IntersectsWith(new Rectangle(PartPos.X, PartPos.Y, m_CircleRadius, m_CircleRadius))) { if (RemoveFood) { m_FoodPellets.Remove(Pellet); } return(true); } } return(false); }