PyRunner

From June 28 through July 12, we worked on an arcade-style game built by dhatch with Python and the PyGame framework: PyRunner.

Python and PyGame are cross-platform, although we had some issues running it on OSX (which we fixed–kinda).

One of my additions was to randomize the block sizes. Here is a bit of code that did that:

class block(scroller):
    def __init__(self, y):
        scroller.__init__(self)
        self.side1 = random.randint(20,100)
        self.side2 = 20
        self.dimensions = random.choice([(self.side1,self.side2),(self.side2,self.side1)])
        self.image = pygame.Surface(self.dimensions)
        self.rect = self.image.get_rect()
        self.y = y
        pygame.draw.rect(self.image, (28,55,183), self.rect)
        self.rect.right = pygame.display.get_surface().get_width()
        self.rect.centery = y
...

You can see one of Python’s cool built-in methods at work: random.choice(…). This method randomly returns one of the options passed in to it. Here, I’m using it to determine if a block will be wide or tall.

Pygame is also used in the code snippet above. pygame.surface(…) prepares an image object, which pygame.draw.rect(…) then draws on the page.

On July 18th, dhatch pulled our changes into a branch of the project: http://github.com/dhatch/PyRunner/tree/1.2pre

See all our changes here: http://github.com/dhatch/PyRunner/pull/4

Advertisements

One thought on “PyRunner

Post your comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s