Original Post
I've been looking for an alternative to PyGame for some time, and finally I can say I've found it. The problems with PyGame are two-fold: first, that it's poorly maintained, and second, that it relies on SDL which - although well tried and tested - is also poorly maintained, and getting quite long in the tooth as a result. Today I finally got around to trying pyglet, and it seems to be a more than adequate replacement for PyGame. I'm always in favour of getting more people to use Python, so they can spend their time making the games they want to make instead of wrestling with the intricacies of C++, and pyglet looks like the best choice currently, for these reasons: - BSD open-source license, good for almost any project, commercial or not; - runs on Windows, Mac OS X, and Linux, with a decent installer for Windows at least; - Uses OpenGL natively for rendering, not DirectDraw, GDI, or some other slow and/or old approach; - Great documentation, including a very readable Programming Guide plus seemingly accurate API docs; - various cool things built in, such as text rendering, playing of streaming audio and video, z-ordering of blits, sprite sheets, all accomplishable in under 10 lines of code. Here, have an OpenGL-accelerated bouncing ball program: All you need to run this is to install pyglet (which requires Python 2.5, or Python 2.4 with ctypes installed), save this as a .py file, ensure you have 2 images in the same directory with the names you supply in the code, and run it. If you want to verify that it's using OpenGL, add "from pyglet import gl" at the top and add "gl.glColor3f(1.0, 0.0, 0.0)" just before background.blit(), and see what you get. It's not perfect yet though: you have to use low-level OpenGL calls to get anything advanced done (eg. glEnable(GL_BLEND) followed by glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) if you want alpha blended sprites), the sprite interface is a bit bare right now (though allegedly this is where Rabbyt comes in), and sound support on Linux seems a little ropey if the docs are accurate. Hopefully nobody minds me posting this; it's not my project and I don't stand to gain anything. I'm just quite excited at Python becoming a more viable platform for our games. Comments and criticisms welcomed, of course.
from pyglet import image
from pyglet import window
# Set these to the size of your background image
win = window.Window(width=768, height=768)
# Set these paths to a couple of graphics
ball = image.load('some_small_image.png')
background = image.load('some_background.jpg')
ball_coords = [0,0]
ball_velocity = [5,3]
while not win.has_exit:
win.dispatch_events()
ball_coords[0] += ball_velocity[0]
ball_coords[1] += ball_velocity[1]
if ball_coords[0] > win.width - ball.width or ball_coords[0] < 0:
ball_velocity[0] = -ball_velocity[0]
if ball_coords[1] > win.height - ball.height or ball_coords[1] < 0:
ball_velocity[1] = -ball_velocity[1]
win.clear()
background.blit(0, 0)
ball.blit(*ball_coords)
win.flip()