Sunday, March 14, 2010

InstaPyGame progress report

I spent the last three days working on a prototype "space shooter" module for my InstaPyGame framework. I had hoped to have a prototype ready today, but the framework isn't usable yet. You can see my progress so far at my Google Code repository, but be warned; the code is messy and inconsistent, and nothing is set in stone.

However, I have created an API with which I'm satisfied. Making the sample below work properly is my goal for this prototype.

from insta.spaceshooter import *

def startDemo():

    game = Game(640, 480)
    player = Player()
    player.when(player.moving, 'left').setSprite('resources/bankingleft.gif')
    player.when(player.moving, 'right').setSprite('resources/bankingright.gif')
    shot = Shot()
    enemy = Enemy()
    boss = Enemy()
    mapGen = LevelMapGenerator({'0' : None, '1' : player, '2' : enemy, '3' : boss})
    level = Level(mapGen.generate('data/levelmap1.txt'))

if __name__ == '__main__':


Right now, I'm working on the event system and the controls, but the event system appears far more challenging. I'm planning to encapsulate the data for the "Player" and "Enemy" objects within another object, protecting the data behind its member functions. This should allow me to create a special data object that will apply its changes only when a condition is fulfilled.

Although the framework is far from complete, I'm excited about the possibilities. I have plenty of work ahead of me, but I think my goal is worth the effort.

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.