Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Snake Grow and Collision Detection | Building a Classic Snake Game
Building a Classic Snake Game
course content

Зміст курсу

Building a Classic Snake Game

bookSnake Grow and Collision Detection

Adding Length to the Snake

One of the key dynamics of our snake game is its ability to grow longer as it consumes food. We provide a method, add_length(), to facilitate this growth:

  • add_length(): Increases the length of the snake by one unit and extends its body by duplicating the last segment.

Collision Detection

For collision detection we will implement method in a way to ensure the flexibility of our game:

  • is_collision(point=None): determines if the snake's head collides with any part of its body OR a given point.

Note

The is_collision() function checks if a point is colliding with any other points in a list. If you don't specify a point, it automatically checks the first point in the list. This setup gives you the option to check collisions for a specific point or default to the first one in the list if you don't specify any.

These collision detection methods enable us to detect when the snake interacts with itself or fruits, allowing us to handle such situations appropriately within the game logic.

Завдання
test

Swipe to show code editor

  • Integrate add_length() method.
  • Implement is_collision() detection methods.

Mark tasks as Completed
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Adding Length to the Snake

One of the key dynamics of our snake game is its ability to grow longer as it consumes food. We provide a method, add_length(), to facilitate this growth:

  • add_length(): Increases the length of the snake by one unit and extends its body by duplicating the last segment.

Collision Detection

For collision detection we will implement method in a way to ensure the flexibility of our game:

  • is_collision(point=None): determines if the snake's head collides with any part of its body OR a given point.

Note

The is_collision() function checks if a point is colliding with any other points in a list. If you don't specify a point, it automatically checks the first point in the list. This setup gives you the option to check collisions for a specific point or default to the first one in the list if you don't specify any.

These collision detection methods enable us to detect when the snake interacts with itself or fruits, allowing us to handle such situations appropriately within the game logic.

Завдання
test

Swipe to show code editor

  • Integrate add_length() method.
  • Implement is_collision() detection methods.

Mark tasks as Completed
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 7
AVAILABLE TO ULTIMATE ONLY
We're sorry to hear that something went wrong. What happened?
some-alt