Pygame Visual Studio Code



Pygame

Programming computer games is fun!

  1. Browse other questions tagged python python-3.x visual-studio pygame or ask your own question. The Overflow Blog Podcast 331: One in four visitors to Stack Overflow copies code.
  2. You can use any editor to edit your code on your computer, but you will find it very helpful to get familiar with a code editor, such as Visual Studio Code. Visual Studio Code supports both Windows and Mac and it's free. To install it, go to and follow the instructions.

Pygame is a library that allows you to create computer games in Python.

Installing Python, Pygame, and Visual Studio Code To provide more flexibility, capability, and better tools for editing and debugging your code we are going to set up our computers with software for developing Python applications, Python games, and Web sites. Visual Studio Code doesn't stop on Python breakpoint debug; int object is not iterable; TypeError: 'frozenset' object is not callable; hide verbose in pip install; Error: The file/path provided (flaskr) does not appear to exist. Please verify the path is correct. If app is not on.

Compared with turtle graphics, you can do even more cool stuff with pygame. For example, you can use it to play better animation, create booming sound, and make your game more interactive.

Installing Pygame

Unlike turtle graphics, which can be run in the CodePad from the browser, you need to install pygame and run it on your computer.

To install pygame, please follow these steps.

Installing Code Editor

You can use any editor to edit your code on your computer, but you will find it very helpful to get familiar with a code editor, such as Visual Studio Code. Visual Studio Code supports both Windows and Mac and it's free.

To install it, go to https://code.visualstudio.com/ and follow the instructions.

Pygame Cheatsheet

You don't have to memorize every pygame instruction. Please check out the pygame cheatsheet and use that as a template to implement your own games.

Hi everyone, from this post we will start learning PyGame. And programming games are real fun, that is why I am here with this PyGame Tutorial for Beginners.

If you are interested in learning game development with python, and you have absolutely no idea about it, then this is the right place for you. I am assuming the readers here are no knowledge of pygame, but you must know the basics of python Ok.

So, let’s start with the very obvious question.

Contents

  • 5 Installation
    • 5.1 Installing Python

What is PyGame?

PyGame is a set of python modules, and these modules are specially designed for writing or coding games. For more information about PyGame you can visit the Official PyGame Website.

What kind of games we can make with PyGame?

You might be thinking what kind of games you can make with PyGame. And honestly speaking it is good for 2D games. And if you are new to game programming then PyGame is good to get started.

You can check this link to see the games that are built with PyGame.

Who can follow this PyGame Tutorial for Beginners?

Any one with the basic knowledge of python can follow this tutorial. You do not need to be an expert or advanced python geek, just a basic understanding of python is more than enough to follow this.

Tools Required

For getting started you just need a simple code editor, notepad++, Visual Studio Code anything is more than enough. But you can also go with some powerful IDE, for example my favourite, JetBrains PyCharm. The community edition is also very very powerful and it is absolutely free.

Installation

Now we have had enough discussion and now we should start the learning part. So we will start from the Installation of PyGame. As this series is called PyGame Tutorial for Beginners, we will cover the installation as well ;).

But before installing PyGame you also need Python and yes it is something obvious.

Installing Python

  • Go to Python’s Website. And download the Python according to your system. In my case I am using Python 3.7, 64bit windows installer.
  • So you just need to download the executable installer (in case of windows) and then you can install it. The installation process is same as you install any other application in your windows computer.

Setting Up Environment Variables

  • Once you have finished installing Python, you also need to setup environment variables. The default installation directory is

C:Users<your user name>AppDataLocalProgramsPythonPython37

  • In the search menu, write environment
  • Select Edit the system environment variables. It will open a new window, from here in the bottom you will see a button named Environment Variables…, click on it and it will open the following window.

Visual Studio Code Tutorial

  • In the bottom box (System variables) click on New…
  • Here you need to write “Path” in Variable name and in Variable value I have the path for the Python installation directory and the Scripts directory which is inside the Python Installation directory, separated by a semi colon (;).
  • Now apply the changes and path are set.
  • To confirm it you can try running python command in command prompt.

Installing PyGame

  • I am using a 64bit, Python but the problem is we do not have an official 64bit PyGame. But we have UnOfficial 64bit PyGame so this is what we will be using.
  • Click on this link, here you will find the unofficial 64bit PyGame Windows Binary.
  • I am using the highlighted one.
  • Now to install PyGame open command prompt and navigate to the directory where you have downloaded the .whl file in command prompt. (In my case it is in my desktop).
  • Now, first you need to install wheel, for this run the following command in command prompt.
2
pip install wheel
ImportPygame
  • And it will install wheel.
  • Now we will run the following command.
2
pip install pygame-1.9.3-cp37-cp37m-win_amd64.whl
  • And also make sure the PyGame WHL file exist in the current directory.

The IDE or Code Editor

Now, this is completely your personal choice, but I think I should tell you what I am using. Python also have IDLE, its own inbuilt editor but I will be using Visual Studio Code, it is again an absolutely free tool.

But yes, it is not necessary that you should also use Visual Studio Code, you can use whatever editor you want to use.

Creating our Game Window

Now let’s do a little coding, and create our very first game window. Excited?. Yes. So let’s begin.

Visual Studio Code Pygame Has No Init Member

  • Create a file named game.py anywhere in your computer. (But it is a good practice to organize your files by keeping them in separate folder, so I would tell that create a folder for your game project).
  • Inside the file game.py write the following code.