Building a game using pygame

Introduction
End Goal
Starting the project
Initializing the game window
Updating the pygame window
Global constants for snake game

Updating the pygame window attributes

Ranvir Singh · 1 mins read ·
python pygame

There are a few attributes in case of pygame window that we can update. Let’s dive a little into so that we know about all the options that we have.

Update the title

The first up in the list is the title of the pygame window. We are going to replace that with the name of our game, PPO snake.

pygame.display.set_caption("PPO snake")

Updating the icon

We can add an image as the icon of the game. I am going to add the image to a new assets directory.

mkdir assets
You can any 32X32 px image. I took a random snake image from flaticon.

For updating the icon, use the following code.

icon = pygame.image.load("assets/snakes.png")
pygame.display.set_icon(icon)

Updating the background color

For updating the background color of the pygame window you can write the following code in the main while loop.

    screen.fill((100, 100, 255))
    pygame.display.update()
It is very important to update the display after we change the color. Otherwise, the change won’t reflect.

The value inside the fill function is the RGB value and you can use any website like this and add a color of your choice.

Updating the pygame window attributes


About Author

Ranvir Singh

Greetings! Ranvir is an Engineering professional with 3+ years of experience in Software development.

Please share your Feedback:

Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!