Posts categorized “Tutorials”.

Pygame Cheat Sheet

If you already know a bit of programming and Python, and want to get up to speed on the Pygame 2D game framework, here’s a cheat sheet that you can look over. It implements a very short Pygame program covering most of Pygame’s basic features.

View the Pygame Cheat Sheet.

You can also download the Pygame program itself, along with the cat.png and bounce.wav files it uses. You will need to install Python and Pygame first to run this program. The program looks like this when you run it:

Pygcurse – A “curses” Emulator Built on Pygame

Pygcurse (pronounced “pig curse”) is a curses library emulator that runs on top of the Pygame framework. It provides an easy way to create text adventures, roguelikes, and console-style applications. The mascot of Pygcurse is a blue pig with a skull tattoo on its butt.

Download Pygcurse and Demo Programs.

Read the Pygcurse tutorial.

View the Pygcurse homepage.

Pygcurse provides several benefits over normal text-based stdio programs:

  1. Color text and background.
  2. The ability to move the cursor and print text anywhere in the console window.
  3. The ability to make console apps that make use of the mouse.
  4. The ability to have programs respond to individual key presses, instead of waiting for the user to type an entire string and press enter (as is the case with input()/raw_input()).
  5. The ability to use any font and any character in those fonts.
  6. Since the console window that Pygcurse uses is just a Pygame surface object, additional drawing and transformations can be applied to it. Multiple surfaces can also be used in the same program.

Pygcurse also provides some additional features that curses normally doesn’t, such as tinting, shadows, textboxes, and line drawing functions.

Pygcurse requires Pygame to be installed. Pygame can be downloaded from http://pygame.org. Pygcurse can be used with either Python 2 or Python 3.

Recursion Explained with the Flood Fill Algorithm (and Zombies and Cats)

This is a programming tutorial for beginner and intermediate programmers who want to learn what recursion is. The programming language used for the examples is Python, but you can probably follow along if you know programming in some other language such as PHP or JavaScript. There’s a lot more information about recursion on the Wikipedia article: http://en.wikipedia.org/wiki/Recursion_(computer_science) But this guide is meant to be a more practical guide to show how handy recursion is.

The source code of everything in this article can be downloaded here: floodfill_src.zip

Consider the Lazy Zombie

This is a cat:

This is a normal human:

This is a normal human who has been turned into an ungodly, flesh-eating zombie of the undead:

Zombies are lazy and will only bite things that are next to them. Humans that are bitten will then turn into zombies:

There is an interesting recursive principle here, because the humans that have turned into zombies will start to bite other humans that are next to them, which will make more zombies, who bite more adjacent humans, which will make more zombies, and so on and so on in a chain reaction:

More… »

Switch to our mobile site