Back to Tutorial Contents
Balloon Ninja on GitHub
In the last section we added some kittens to the game to make it more challenging, and we cleaned up Engine.py to be a true class. In this section we will post our project to GitHub, and make a list of features we’d like to implement if we were to take this project further.
If you are unfamiliar with it, GitHub is a site for posting open-source projects. When a project is posted to GitHub, people can access your source code directly. They can contribute to your project, or they can “fork” your project and take it in their own direction. Before adding a project to GitHub, it is important to include a README file, and it is a good idea to include a LICENSE file as well. Here is the README.txt file for balloon_ninja:
Balloon Ninja is a simple game, intended to help beginners learn the Pygame framework. Balloon Ninja is maintained by Eric Matthes: firstname.lastname@example.org @ehmatthes There is a full tutorial writeup at: https://peak5390.wordpress.com/2012/12/17/balloon-ninja-a-simple-pygame-tutorial/ Requirements: pygame To run, checkout the repo and run balloon_ninja.py: $ python balloon_ninja.py License: Balloon Ninja is released under the MIT License. See LICENSE.txt
There are a few basic things that go into a README file. We tell people a little about the project. We tell them who we are, and we may give people a way to contact us if they want to help out on the project. We can link to outside resources related to the project, such as this tutorial. We list the requirements for running the project, such as pygame for this project. We tell people how to run the project once they have it loaded onto their local machine. Finally, we state how the project is licensed.
There are an abundance of open-source licenses available to choose from. If you have not thought much about licensing before, it’s a good idea to visit the Open Source Initiative site. There are a few common open-source licenses that should fit most people’s needs. The MIT license is a standard OS license, and should fit the purposes of this project. Briefly, the MIT license is a permissive license which allows people to “use, copy, modify, merge, publish, distribute, sublicense, and/or sell” the software. If anyone redistributes the software in any manner, they need to include the original copyright and the original MIT license.
To use the MIT license, you simply copy and paste the text of the license into a LICENSE.txt file, and include your name and the copyright year:
Copyright (c) 2013 Eric Matthes Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Now we have a complete project which we can push to a GitHub repository. I won’t go into a full explanation of how to use git here, but if you know how to use git locally I’ll give brief directions for posting your project to GitHub. To post the project, you need a GitHub profile. Once you have registered at GitHub, click “New Repository”. Give your project a name, which should probably match the local name of your project. Then within your local project directory, issue the command:
git remote add origin https://github.com/username/balloon_ninja.git
Now you can push your local project to your GitHub repository:
$ git push origin master
This pushes your current master to your new GitHub repository. Here is what Balloon Ninja looks like on GitHub:
Once we have a repository created, anyone can run our project. To try it out, navigate to a directory where you want to download a copy of the program and issue the following commands:
$ git clone git://github.com/ehmatthes/balloon_ninja Cloning into balloon_ninja... remote: Counting objects: 29, done. remote: Compressing objects: 100% (23/23), done. remote: Total 29 (delta 6), reused 27 (delta 5) Receiving objects: 100% (29/29), 18.31 KiB, done. Resolving deltas: 100% (6/6), done. $ cd balloon_ninja balloon_ninja$ python balloon_ninja.py
The “clone” command creates a copy of the remote repository on your local system. The repository is created in its own directory in the current location. To run the program, cd into this new directory and run the main program file.
Where to go from here?
My main goal in writing this tutorial was to help people get started in using Pygame, by demonstrating the kind of thinking that goes into creating a game. Hopefully this has helped you become more comfortable starting to create your own game. If we were to develop Balloon Ninja further, there are many things we could do to make it more fun and interesting. Here are a few ideas:
- Add a “Pop All” feature. When the player presses the space bar, all balloons in the current batch are popped, and you get points for them all. You start out with one PopAll, and you can earn more at certain point levels. Pop All leaves kittens to rise to the top of the screen on their own, where they will be scored.
- Add sound. The balloons make a popping sound when they are slashed, kittens cry out when they are slashed. Maybe balloons and kittens make different sounds as they rise off the screen.
- Add difficulty settings. Players can control the settings that affect overall game play, such as speed scale, kitten ratio, batches needed to increase batch size, etc.
- Keep track of the high score.
- Scale the size of balloons and kittens. Balloons get smaller as the game progresses, and kittens get larger.
- Add a randomized balloon size factor. In each batch, their will be different size balloons. If you do this, make the point values an attribute of each balloon, so that smaller balloons can be worth more than larger balloons.
- Add “wind” to make the balloons drift horizontally. Let wind value take a random walk. This means the wind speed is initially 0. Pick a random number between 0 and 1. If the number is greater than 0.5, increase the wind speed. If it is less than 0.5, decrease the wind speed.
If you are just learning Pygame, it might be fun to try to implement any number of these features. If you do something interesting with Balloon Ninja, please get in touch and share your final version.
If you are about to make your first game, and you want to keep things simple, consider making a game that only involves horizontal and vertical motion. Try to clone a game such as Space Invaders, or make a simple game where you have to move a character out of a maze. Once you are comfortable with the Pygame framework, you can move on to more advanced games. Also, you might want to look at the “projects” sidebar on the Pygame home page. There is a long list of games you can download and play, and then explore the sourcecode to see how the game was implemented. For example, here are a number of Space Invaders clones.
If you have any feedback, please feel free to get in touch. If you have any questions, please feel free to post them to the comments and I will be happy to answer them there. Thank you for reading, and good luck with your games!
Back to Tutorial Contents