![]() ![]() W00t the bunny is in the scene, and ready for action!īut the game looks scary and lonely with the bunny just standing there on a black background. If you run the code now (via Run\Run Module in the Idle menu), you should see a screen similar to the one below: However, at least on Mac OS, the game would hang on exit unless pygame.quit() was called. ![]() Note: According to the PyGame documentation, you shouldn’t need to call pygame.quit() since the interpreter will automatically call it when the interpreter shuts down. Keep looping over the following indented code.Load the image that you will use for the bunny.Initialize PyGame and set up the display window.This allows you to use functions from the library in your program. Let’s go through the code section-by-section: Save the file into your game folder (the one where the resources subfolder is) and name it game.py. # 5 - clear the screen before drawing it again Type the following code into the editor window: Run IDLE and open a new text editor window, as mentioned in the previous section. You are now ready to begin creating Bunnies and Badgers. Once you’ve downloaded the file, create a folder for your game on your hard disk and extract the resources folder into that folder so that your game folder has a subfolder named resources, with the various resources grouped in additional folders inside it, like this: You can download it via the Download Materials button at the top and bottom of this page. But what’s a game without some great graphics and sound effects? I’ve put together all the graphics and sound effects you’ll need for your game into a ZIP archive. You are almost ready to create your game. You can save your code changes via File\Save and even run the code via Run\Run Module (F5).ĭo note that the Run menu is only available if you have a file open in an editor window. Then choose File\New Window from the IDLE menu and you should have a text editor window where you can type in Python code. To run idle, simply type idle from Terminal. The other way is to type in your code using the IDLE editor, which is what you’re going to do in this tutorial. On Mac, open Terminal and type python, then drag the file that you saved onto the Terminal window and press Enter. Then on Windows, double-click this file to run it. Then save it as XXX.py (The XXX can be any descriptive file name). Open a new text file, type in your Python code (like print 1 1). One way is to use a plain text editor like Notepad (Windows), or TextEdit (Mac). There are several ways to run a Python program as a file. While you can run short bits of Python code at the Python prompt, if you want to work on a bigger program (like a game), you probably want to save your code to a file so that you don’t have to type it in over and over again. If you get an error like this, post on the forums and I will help you get it working. Type "help", "copyright", "credits" or "license" for more information. If, on the other hand, it outputs an error like what’s shown below, then PyGame is not installed. If this doesn’t result in any output, then you’re good. To verify that you have PyGame installed properly, open IDLE or run Python via the Terminal and type in import pygame at the Python prompt. Or, you can install both Python and PyGame via MacPorts. You’ll need to download Python from and install it in order to use PyGame. Note: The PyGame installer from the link above will not work with the default Python from Apple that is installed on a Mac. If you are on a Mac, you already have Python installed! Just open Terminal (/Applications/Utilities/Terminal.app), type in python and press Enter. Make sure you grab the 2.7.3 version and NOT the 3.3.0 version! After running the installer, you should have IDLE in your All Programs folder in your start menu. If you want to try this tutorial on a Windows PC, you need to install Python. Keep reading to jump into the fray! Getting Started: Installing Python Then dive back here and get ready – there’s a war coming on between the bunnies and the badgers. If you are new to Python, before you begin check out this book: Think Python: How to Think Like a Computer Scientist. We chose Python for this tutorial because it’s a simple language to start out with, and is fun and easy to learn. Python is a computer programming language. No, I’m not talking about a big snake! :] In this tutorial, you’ll create a simple game called Bunnies and Badgers, where the hero, the bunny, has to defend a castle against an attacking horde of badgers. Have you ever wondered how video games are created? It’s not as complicated as you might think! This is a post by Tutorial Team Member Julian Meyer, a 13-year-old python developer. Learn how to make a simple game with Python! ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |