![]() ![]() The last two numbers represent the size of the rectangle, 10 by 10 pixels.The first two numbers 200 & 150 represent the X and Y coordinates for where to display the rectangle.The coordinates to draw the rectangle on the screen and how big it should be.The colour this rectangle should be (define a variable blue with the HEX value for the colour blue).The display we want to update (the screen variable in our case).To draw graphics on the screen like a rectangle for our snake, we’ll need to call, passing in the following as arguments: Okay, we’re done getting excited about windows now. This is all it is now, but it will become a functional snake game □ If we run the script as it is now, we should see a little window with a black background pop up on the screen! You can also increase it to make the game more challenging! This is not super necessary, however if you find that the snake moves too fast you can make snake_speed a smaller value. The clock variable allows us to specify how fast our game should update. It’s also important that we move any updates we make to the screen inside the loop, so we’re constantly updating the contents of the screen on each frame. If you don’t have () running in a loop, your game won’t really work. You can think of executing () like walking the next “step” your game will take. Open a command prompt and type in pip install pygame, wait a little and pygame should be available to use in your code.Įnter fullscreen mode Exit fullscreen mode pygame allows us to quickly develop a game and handles all the complicated logic for us. We’ll need to install the pygame dependency to make our game, and we can install it by using pip on the command line, which comes with the Python installation. ![]() It’s called a dependency because our code depends on the other person’s code to work. To achieve that, we’ll need to install a dependency.Ī dependency is code from another location that we import into our code. We want our snake game to appear in a window that the user can interact with, like any other application. py extension, this means it’s a Python script which we’ll be able to run from the command line later. Having an IDE is helpful for catching errors and knowing when your syntax is wrong quickly, but you can always program using a normal text editor, like Notepad or TextEdit. Click “Download Python (version)” and go through the installation process. If you haven’t already installed Python, you can download it from here. In this guide, we’ll walk through the basics of setting up a Python installation, creating a window to display our game, and updating the window with a fully functional snake game. Python is a beginner-friendly language that makes it easy to dive straight into making your own games with a graphical user interface (GUI). ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |