VOOZH about

URL: https://www.geeksforgeeks.org/python/dodger-game-using-pygame-in-python/

⇱ Dodger Game using Pygame in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dodger Game using Pygame in Python

Last Updated : 23 Jul, 2025

A Dodger game is a type of game in which a player has access to control an object or any character to dodge (to avoid) upcoming obstacles and earn points according to the number of items dodged if the player is not able to dodge the object the game will be over and final score will be displayed in the console. After certain points or times the speed of the objects to be dodged increases which makes it harder and harder to score more points. The player can control the movement through some input from some input devices, it can a keyboard, a joystick, a game controller, etc..

Building a Dodger Game using Pygame

Installation of the required Python library

First, we need to install the Pygame library in the system, to install use the following command and run the command in the command prompt (for the Windows operating system).

pip install pygame
👁 Screenshot-2024-08-14-012043
After Executing the command.

Importing the library to use it inside the Python code

After Importing we can use the pygame properties.

Declaration and initialization of variables

The Screen Height , Width is declared along with come colors and the frame rates.

Declaration of the players details and the objects that need to be dodged

The variables are created to declare the size of the player , the movement ,the speed and similarly for the dodged object.

Deceleration of the the function

This function basically checks for the collision between the player and the random object which need to be dodged.

Wrapping the code

The code is iterated by using a while loop and condition that until the condition for game over become false this will work and update the score values and increases the speed of the objects after certain points and it will display the final score if the game is over (player could not able to dodge).

Complete Code

NOTE: User can customize the code according to the choice and can add more features to the code depending upon the requirement.

Output

👁 Screenshot-2024-08-14-020926
Initial score
👁 Screenshot-2024-08-14-021137
Here the blue color indicate the player and the red color is the object
👁 Screenshot-2024-08-14-021322
When the game is the over the final score is displayed.


Comment
Article Tags:
Article Tags: