Sunday, March 7, 2010

GSoC project idea: Insta-PyGame

I'm still trying to choose new GSoC organizations to join, but I know one of the organizations to which I'll apply: PyGame, the SDL-based Python multimedia library. I plan to write a micro-framework on top of PyGame to dramatically simplify the creation of conventional games.

The Problem

PyGame is a wrapper for the C SDL library. Some of the library hides the complexity of the underlying SDL library, but in most areas, PyGame is simply a Python binding for SDL. For that reason, you often need to write several lines of code to accomplish a simple task, such as checking whether the user has pressed a button. In addition, many pieces of the API are based on C coding idioms that are unfamiliar to most Python programmers.

The Plan

I propose the development of a new framework on to of PyGame that operates at a much higher level of abstraction. Through this new framework, people would create games by declaring the sprites the characters use, the arrangement and graphics of the levels, and the interactions between the player and the contents of the levels.

The framework would be divided into modules with each module representing a genre. The "platformer" module would contain everything necessary to create a platformer game, including a physics engine, a tile map engine, and enemies that die when you jump on them. In contrast, the "scrolling shooter" module would contain tools for controlling the behavior of projectiles and enemy ships.

Here's an example of the type of code games using the framework could look like. I haven't put much thought into the API, but I would like game code to be written at this level of abstraction.

from import *

from insta.platformer import *

def startMenu():

    titleScreen = Screen(600, 400)
    titleScreen.setTitle("Porcupine's Tiny Adventure")
    titleScreen.setOptions(["Play", "Controls", "Credits"])
    # More code for other menu options

def startGame():

    game = Game()

    hero = Player()
    hero.setRunningSprites(["running1.gif", "running2.gif", "running3.gif"])


    goal = Item()

    itemGenerator = ItemGenerator([None, goal, hero])

    Tile generator translates level maps (text files full of numbers) into tile
    maps in a context-sensitive manner
    tileGenerator = TileGenerator()
    # Edge and corner sprites could also be set

    mushroom = Enemy()
    mushroom.setRunningSprites(["step1.gif", "step2.gif"])
    # Some simple behaviors would be pre-defined

    bird = Enemy()
    bird.setFlightSprites(["flap1.gif", "flap2.gif"])

    # List associates enemy types with numbers in the text file
    enemyGenerator = EnemyGenerator([None, mushroom, bird])

    level = Level()

    level.setBackgroundOptions([constants.TILED, constants.PARALLAX])


if (__name__ == "__main__"):


The Goal

I want to free PyGame developers from thinking about the hows of game development, allowing them to focus on the whats of their ideas. By freeing game creators from thinking about the implementation of their games, I hope to allow them to explore new ideas in video game design, such as dynamically-generated levels, media mashups, user-created content, and AI.

This is just a rough outline of the framework I'd like to build and the effects I hope to see. I plan to start work on a prototype soon if the PyGame community appears receptive to my idea.