Game Development in Python, ruby or LUA?
Question: I have experience in game development in some game engines in Action Script 3
and C++. However, I would like to improve the productivity and so I want to
develop a new project in Python, ruby or LUA. Would it be a good idea? If yes,
which one would you suggest? and what is the killer game development tool set
or engine?


Answer: If you're any good, go with [Pyglet](http://www.pyglet.org/).  
It's a cross-platform Python version independent hook against OpenGL with
outstanding performance. It's a bit tricky but it does the job better than
anything else out there in the Python world.

If you're a beginner, i'd go with [Pygame](http://www.pygame.org/).  
It's a bit taxing on the system but with a modern computer that isn't a
issue.. also, it got pre-packaged API's for game development (hence the name)
:)

A "official" list of Python gaming/graphic engines:
<http://wiki.python.org/moin/PythonGames>

Some good ones:

  * Panda3D
  * Pyglet
  * PyGame
  * Blender3D

# Example Pyglet code:

    
    
    #!/usr/bin/python
    import pyglet
    from time import time, sleep
    
    class Window(pyglet.window.Window):
        def __init__(self, refreshrate):
            super(Window, self).__init__(vsync = False)
            self.frames = 0
            self.framerate = pyglet.text.Label(text='Unknown', font_name='Verdana', font_size=8, x=10, y=10, color=(255,255,255,255))
            self.last = time()
            self.alive = 1
            self.refreshrate = refreshrate
            self.click = None
            self.drag = False
    
        def on_draw(self):
            self.render()
    
        def on_mouse_press(self, x, y, button, modifiers):
            self.click = x,y
    
        def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
            if self.click:
                self.drag = True
                print 'Drag offset:',(dx,dy)
    
        def on_mouse_release(self, x, y, button, modifiers):
            if not self.drag and self.click:
                print 'You clicked here', self.click, 'Relese point:',(x,y)
            else:
                print 'You draged from', self.click, 'to:',(x,y)
            self.click = None
            self.drag = False
    
        def render(self):
            self.clear()
            if time() - self.last >= 1:
                self.framerate.text = str(self.frames)
                self.frames = 0
                self.last = time()
            else:
                self.frames += 1
            self.framerate.draw()
            self.flip()
    
        def on_close(self):
            self.alive = 0
    
        def run(self):
            while self.alive:
                self.render()
                # ----> Note: <----
                #  Without self.dispatc_events() the screen will freeze
                #  due to the fact that i don't call pyglet.app.run(),
                #  because i like to have the control when and what locks
                #  the application, since pyglet.app.run() is a locking call.
                event = self.dispatch_events()
                sleep(1.0/self.refreshrate)
    
    win = Window(23) # set the fps
    win.run()
    

  

* * *

  

# Note on Pyglet with Python 3.X:

You'll have to download the **1.2alpha1** otherwise it will complain about you
not having Python3.X installed :)

