BAM Weblog

PyWeek - 8 pixels and Python reloading

Brian McKenna — 2011-08-28

I’m organising a team entry into next month’s PyWeek (#13) - this week I did a bit of preparation.

Walk cycle in low resolution pixel art

Time is always limited during PyWeek. To make a nice looking game, you have to be able to rapidly create art. I’ve been working on minimising the amount of pixels used. I think this has two direct benefits:

  • Low resolution graphics look nice
  • They are very quick and fairly easy to create

Ideally I want less than 8x8 pixel characters but I’ve found that it’s hard to create a nice looking walk animation with limited pixels. My first take was to create characters with 1px high legs:

It’s not very obvious that the character is walking. I thought that some shading might improve the situation:

Only a little. Next thought was that the legs just don’t have enough definition. Adding a knee helped a bit:

Adding some shading to the legs helped even more:

But I wanted something more fluent. I wasn’t sure how to create it with the platformer side/front on view like above but I had an idea of how I wanted it to look side on:

Looks nice! I took the animations of each leg and added it back to the platformer angle:

The legs look like a mess half-way into the animation. I thought it might be caused by the legs being too close together. I moved them apart by a pixel:

It actually looks pretty good! But then I thought, is it really much of an improvement to one of the simpler ones?

In the end, I’m not sure if it’s worth the extra work when you’re under heavy time constraints.

Reloading Python modules

This PyWeek I want to try to write the game in a style that will allow for reloading of parts while it’s running. It turns out that Python has a reload built-in that’s makes this really simple!

I made a small proof of concept. I created a file called “constants.py” that included a single constant:

SPEED = 10

I then wrote some game code. Pressing the right key will move the player to the right by SPEED pixels. Pressing ‘r’ will reload the constants.py file. Using Pyglet:

#!/usr/bin/env python
import pyglet
import constants

window = pyglet.window.Window()

animation = pyglet.image.load_animation('Cycle7.gif')
sprite = pyglet.sprite.Sprite(animation)

@window.event
def on_draw():
    window.clear()
    sprite.draw()

@window.event
def on_key_press(symbol, modifiers):
    if symbol == pyglet.window.key.RIGHT:
        sprite.x += constants.SPEED
    elif symbol == pyglet.window.key.R:
        reload(constants)

pyglet.app.run()

So while running, I can modify constants.py:

SPEED = 100

Then switch back to the game, press ‘r’ and then press the right button to move the character by 100 pixels! Hopefully this will let us rapidly play with game values without having to exit and restart the game.

Please enable JavaScript to view the comments powered by Disqus.