Posts categorized “Blog”.

“I Need Practice Programming”: 49 Ideas for Game Clones to Code

So you know a little bit about programming (perhaps you’ve read the free book, “Invent Your Own Computer Games with Python”, a free programming book for beginners whose author shamelessly plugs at every chance) but you want to get better at coding. You can’t seem to find any open source projects that are at your level or easy for new people to contribute to. You’ve gone through a few of the practice problems at Project Euler but you want to create something more substantial, or at least a cool thing you can show your friends. (Not that finding the 31337th prime number isn’t cool.)

Here’s a list of game clone ideas for you to implement. Each has a short description of the game, links to videos of the game, and descriptions of what kind of algorithms you’ll need to know in order to implement them. These games have been selected for their simplicity, so you don’t have to spend several weeks designing art, levels, scripted dialogue, or complicated AI. These are clones designed to be doable in roughly a weekend. A Mario or Zelda clone would be complicated to put together, but a Tetris or Asteroids clone would be doable in a weekend.

Orisinal Games:

The Orisinal website has a great collection of Flash games with very simple mechanics that can be copied. http://www.ferryhalim.com/orisinal/

I especially recommend Winter Bells, A Daily Cup of Tea, Bugs, and Hold the Rope!

The Wikipedia entry for video game clones also lists some ideas.

Games from “Invent Your Own Computer Games with Python” and “Making Games with Python & Pygame” books:

These games are described in these free Python programming books and their source code is available. However, you can make your own variants.

1. Dodger

Description: Several bad guys fall from the top of the screen, and the user must avoid them. The player can be controlled with the arrow keys or more directly with the mouse. The longer the player lasts without being hit, the higher the score.

Variations: Have enemies fall at different rates and be different sizes. Have enemies fall from more than one side of the game. Have power up pickups that grant invulnerability for a while, slow down bad guys, give the player a temporary “reverse bad guys” power, etc.

This game is covered in Chapter 20 of “Invent with Python”

Download Source: dodger.zip

2. Memory Puzzle

Description: A board full of overturned cards. There is a pair for each card. The player flips over two cards. If they match, then they stay overturned. Otherwise they flip back. The player needs to overturn all the cards in the fewest moves to win.

Variations: Provide “hints” in the form of four possible matching cards after the player flips the first one. Or, quickly overturn groups of cards at the beginning of the game.

This game is covered in Chapter 1 of “Making Games with Python & Pygame”

Download Python Source: memorypuzzle.py

More… »

Pyganim – A Pygame module to make sprite animation dead simple.

Download pyganim.py and example programs. (Works on both Python 2 and 3.)

Details at http://inventwithpython.com/pyganim/

Pyganim is a module that you can import into your Pygame games to handle sprite animation. Creating an animation is simply a matter of supplying a list of image filenames (or pygame.Surface objects) for each frame of animation, along with the duration that each frame lasts. Then call the play() method to start the animation and then call blit() each time you draw the window. The blit() function automatically draws the correct frame based on the amount of real time that has passed since the play() method was called. There are many, many other methods to provide finer levels of control as well.

There is more information available on the Tutorial and Reference page.

The Things I Hate About IDLE That I Wish Someone Would Fix

I’ve written a book on Python programming for kids and complete beginners. I’ve also done some classroom and one-on-one teaching with adults and teens. I have them use IDLE, the IDE that comes with Python, because it is simple and easier than having them set up some other IDE (like PyDev on Eclipse).

But over time I’ve noticed a lot of problems with IDLE that I wish someone would fix. (I’d like to do it myself but I don’t have the time currently.) I’m very, very grateful that Python comes batteries included vis-à-vis an IDE, but there are a lot of warts and user interface issues with IDLE. (These are different from the bugs listed on the python.org bug tracker.)

First off, my philosophy is that no serious Python programmer uses IDLE as their dev environment. With that assumption, we can get rid of any need to cater to them and make IDLE aimed at people who are not only new to Python but new to programming in general. IDLE should be an education tool more than a development tool. This means that the IDLE default options should all be set for the basic user, not the power user.

With that in mind, these are things I’d like to see changed about the design of IDLE (roughly in order of importance and prior More… »

List of Street Names, List of Last Names

I wrote some programs to go through 6 GB of OpenStreetMap data from http://metro.teczno.com so that I could extract a list of street names for an upcoming game project. The game will use procedural generation to create cities, so I need to have a dataset of street names but couldn’t easily find one. So I’ve created this one and wanted to share it.

Download zip file of street names. (805 KB)

I did a lot of tweaking to remove duplicates. Each street name is on its own line, and you can just add “Rd”, “St”, “Ln”, “Ave”, “Blvd”, “Pkwy” or any other suffix to the end of it. The zip file has a file of street names from each city, and then an allstreets.txt that has all of them combined into one file (with duplicates removed). Streets with numbers have been removed (there is no “7th” but there might be “Seventh”).

The street data comes from Boston, Chicago, Leeds, London, Manchester, St. Paul, New York, Seattle, the San Francisco Bay Area, Sydney, and DC, so you can expect that they mostly have Anglo names.

Then after looking at the data for a while, I realized that these could also be used for Anglo last names. I’ve removed any words that appear in a dictionary file I have, so some common last names like “Smith” or “Hunting” won’t show up. I would consider this list of moderate quality. Here’s the list:

Download zip file of last names. (171 KB)

I can’t vouch for the quality of the lists, but from a cursory inspection they seem quite serviceable. Enjoy!

Rough Drafts of Next Two Books Available

I’ve decided to make the incomplete rough drafts of my next two Python books available.

Become a Codebreaker with Python

Making Graphical Games with Pygame

The emphasis is on “rough” and “incomplete”, but I thought it would be better to give a preview of the direction I was going. These books are also available under a Creative Commons BY-NC-SA license like the first “Invent with Python” book.

The Code Breaker book is aimed at complete beginners who have never programmed before, and as such has a lot of the same content as Invent with Python. It covers various encryption programs, and also how to write programs that can break encryption. (It’s an intro to programming and cryptography at the same time.)

The Pygame book is aimed at people who have read the first book or have a moderate amount of Python experience, and want to learn how to use the Pygame library to make graphical games. So far, the book really only has the source code for the games that will be in the book (these are the same programs that have been featured on this blog before.)

Hope you enjoy them. Feel free to send any ideas on content or presentation to me (don’t bother with typos and such, these are incomplete drafts and those are probably known issues.) [email protected]

 

 

 

 

 

Nobody Cares About a Few Million Nanoseconds

A Clever Programming Trick…

If you need to swap the values of two variables, this usually requires a third temporary variable (that is, if you’re not using a language like Python that supports the a, b = b, a syntax.) It looks something like this:

temp = a;
a = b;
b = temp;

But if these are integer variables, there’s a nifty trick to save yourself a little bit of memory. You can use arithmetic instead of a temporary variable:

a = a + b;
b = a - b;
a = a - b;

If the integers on your platform are 32-bits, your new swap will save four bytes of memory.

NOBODY CARES ABOUT FOUR BYTES OF MEMORY. More… »

Switch to our mobile site