This repository contains the code for a video tutorial on creating a simple collision detection system using Pygame in Python.
In this tutorial, we build a basic Pygame application that demonstrates collision detection between a player-controlled character (Dino) and an obstacle. The tutorial covers setting up the Pygame window, updating the character's position, detecting collisions, and visually representing the collision state.
- Pygame Window Setup: Initialize a Pygame window with a specified width and height.
- Dino Character: A player-controlled character that can move and interact with obstacles.
- Obstacle: A static rectangular obstacle positioned within the game window.
- Collision Detection: Real-time detection of collisions between the Dino and the obstacle.
- Visual Feedback: Visual representation of the obstacle and collision state.
- main.py: The main script that initializes the Pygame window, handles events, updates the Dino's position, checks for collisions, and renders the game objects.
- dino.py: A separate module containing the
Dino
class, which manages the character's position, rendering, movement, and collision detection.
-
Clone this repository:
git clone https://github.com/educ8s/pygame-collisions-tutorial.git cd pygame-collisions-tutorial
-
Ensure you have Python and Pygame installed. You can install Pygame using pip:
pip install pygame
-
Run the
main.py
script:python main.py
- Run the script and a window titled "Pygame collisions" will appear.
- The
Dino
character can be moved using the arrow keys on the keyboard. - The obstacle is drawn as a black rectangle.
- If a collision occurs, visual feedback will be provided.
- Python 3.x
- Pygame
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.