Posts Tagged ‘ pygame

What to make a game in, part 2

After some serious thinking (based on my previous post), I’ve decided to go with PyGame as my initial platform for making a game.  As much as I like Processing for making ‘interactive visuals’, the more I learn Python, the more I like it (as in, the language itself… Python has no great graphics abilities on its own).  The syntax is just so much cleaner than Java (Processing).  I also looked closely at XNA, but approaching C# doesn’t give me any great joy, based on its structural similarities to Java.  There is a huge XNA community, and I’ll probably come back to at during some point.  I also took a serious look at Blender, and its game creation system.  But since I’m so used to Maya as my DCC tool, switching to Blender was really hard.   You can’t change the hotkeys!  It’s just too much for me :)  Maybe when version 2.5 comes out…   So for now,  PyGame FTW!

I have picked up some books on the subjects to supliment the vast quantity of tutorials on the web:

PyGame:

XNA:

And while I was at it, got one on the Arduino, since you never know when that will come in handy 😉

I’ve already got a simple 2-‘player’ game up and running where you can drive two ‘tanks’ around the screen.  A pleasing start.

On a side note, my Xbox 360 got the RROD last night.  Sigh…

First PyGame program

Based on my previous post of researching viable applications to make a simple game in, I decided to delve a bit into PyGame.

Since my brain is so heavily inundated with making Processing sketches, I based the code structure around core Processing concepts (setup() function, draw() function, etc).  While it’s probably not the best solution for writing a PyGame app (the liberal usage of ‘global’ calls), it does actually run, which is all I wanted :)

What does it do?  Spawn a bunch of random circles and have them bounce around the screen.  Exciting?  Not very.  But, you gotta start somewhere 😉

# pyGameTest02.py
# Eric Pavey - 2009-04-06
# Writing a PyGame app that emulates the general program layout of a Processing sketch.
# Makes a bunch of random circles bounce around.

import pygame
from pygame.locals import *
import random

RES = [640, 480]
MAXCIR = 128
window = None
screen = None
circles = []

class Cir(object):
    # Make our circle objects

    def __init__(self):
        self.xPos = RES[0]/2
        self.yPos = RES[1]/2
        self.xDir = random.choice([random.uniform(0,2),random.uniform(-2,0)])
        self.yDir = random.choice([random.uniform(0,2),random.uniform(-2,0)])
        self.radius = random.uniform(8,64)
        self.width = random.uniform(2,8)

    def move(self):
        self.xPos = self.xPos + 1 * self.xDir
        if self.xPos + self.radius/2 + self.width > RES[0] or self.xPos < self.radius/2 + self.width:
            self.xDir = self.xDir * -1

        self.yPos = self.yPos + 1 * self.yDir
        if self.yPos + self.radius/2 + self.width > RES[1] or self.yPos < self.radius/2 + self.width:
            self.yDir = self.yDir * -1            

    def draw(self):
        # must make all vals int:
        pygame.draw.circle(screen, Color('white'), [int(self.xPos), int(self.yPos)], int(self.radius), int(self.width))

    def run(self):
        self.move()
        self.draw()

def setup():
    # Initialize startup parameters
    global window
    global screen

    pygame.init()
    window = pygame.display.set_mode(RES)
    pygame.display.set_caption('PyGame Test 02')
    screen = pygame.display.get_surface()
    screen.fill(Color('black'))

def draw():
    # Run main loop:
    global screen
    global circles

    run = True
    while run:
        screen.fill(Color('black'))
        for c in circles:
            c.run()
        if len(circles) < MAXCIR:
            circles.append(Cir())
        pygame.display.update()

        for e in pygame.event.get():
            if e.type == QUIT:
                run = False
                break

if __name__ == "__main__":
    setup()
    draw()

What to make a game in?

I’ve been wanting to do a simple interactive game for some time now.  Conceptually, it’d not be very complex, and stylistically, look like childrens drawings.

I’ve been teaching myself Processing for some time now, and am fairly well versed scripting in Python via my day to day tasks working in Maya.

Processing seems like a good medium for this, and I’ve seen some fairly complicated games written in it recently.  But it’s strengths are based more around making good quality  ‘generative art’ (in my opinion), rather than full-featured game applications.  Plus its provided IDE (coined the ‘Processing Development Environment‘) doesn’t seem robust enough to handle larger scale game dev.  And… I really don’t feel like tackling installing Eclipse, learning more about Java, and getting Processing to run in that (but it would be a more viable option at that point).

Python has a very extensive library called PyGame, that seems like a real contender.  Since I’m (currently) only interested in doing a 2D side-scroller, this could be the method of choice.

However, lately I’ve been researching Blender.  It’s a full featured 3D DCC that’s both open-source and based entirely on Python.  Furthermore, it comes with it’s own built-in game engine.  I find this whole package very attractive, but as of yet have no experience with it.

Finally, most robust (seemingly), but something I have the least amount of experience with, would be Microsoft’s XNA Game Studio Express.  You can use Visual Studio Expression Edition to author it (I believe this is in C#), and then play games directly on your Xbox 360.  Very slick.  But the most learning required.  More info at that XNA Creators Club.

So time will tell!  But the best part is whatever I choose, I still win.  Good fun.