VOOZH about

URL: https://www.geeksforgeeks.org/python/python-arcade-collision-detection/

⇱ Python Arcade - Collision Detection - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Python Arcade - Collision Detection

Last Updated : 5 Oct, 2021

In this article, we will learn How we can add collisions in arcade games in Python.

Installation

You can install the Arcade module using the below command:

pip install arcade

Example 1:

In this example, we are going to use the check_for_collision() function to add collision between 2 sprites.

Syntax: arcade.check_for_collision( sprite1, sprite2)

Parameters:

  • sprite1:- First sprite
  • sprite2:- Second sprite

Returns: Boolean value

Sprites Used:

👁 Image
👁 Image

Below is the implementation:

Output:

👁 Image

Example 2:

In this example, we are going to use PhysicsEnginePlatformer() function to add collision between our player and platform.

Syntax: arcade.PhysicsEnginePlatformer(player_sprite, platforms,, gravity, ladders)

Parameters:

  • player_sprite:- The player sprite
  • platforms:- The platform sprite list
  • gravity:- Amount of gravity
  • ladders:- Ladders the user can climb on

Sprites Used:

👁 Image
👁 Image

Below is the implementation:

Output:

👁 Image
Comment
Article Tags:
Article Tags: