private void FoodCollision() { // Finds last snakePixel in the list PictureBox lastPixel = snake.snakePixels[snake.snakePixels.Count - 1]; //Declare by one variable the first list element PictureBox head = snake.snakePixels[0]; // If snake head cross food borders creates new food and adds new snakePixel if (head.Bounds.IntersectsWith(food.Bounds)) { food.AddFood(); snake.AddPixel(lastPixel.Left, lastPixel.Top); snake.Render(this); } }
private void SnakeFoodCollision() { if (snake.snakePixels[0].Bounds.IntersectsWith(food.Bounds)) { //increase score score += 10; //regenerate food SetFoodLocation(); //add new pixel to the snake int left = snake.snakePixels[snake.snakePixels.Count - 1].Left; int top = snake.snakePixels[snake.snakePixels.Count - 1].Top; snake.AddPixel(left, top); snake.Render(this); if (mainTimer.Interval >= 20) { mainTimer.Interval -= 20; } } }
private void SnakeFoodCollision() { if (snake.snakePixels[0].Bounds.IntersectsWith(food.foodCollection[foodIndex].Bounds)) { score += 10; lblScore.Text = "Score : " + score; SetFoodLocation(); int left = snake.snakePixels[snake.snakePixels.Count - 1].Left; int top = snake.snakePixels[snake.snakePixels.Count - 1].Top; snake.AddPixel(left, top); snake.Render(this); if (score >= 200) { LevelCompleted(); } if (mainTimer.Interval >= 20) { mainTimer.Interval -= 20; } } }