Tag Archives: game

Workshop: Journey to the Center of Hawkthorne

At our next open source workshop, Shawn Shaefer will be showing us how to build and contribute to Journey to the Center of Hawkthorne, a 2D platform-type game based on a game from an episode of Community. The game is written in Lua with the LÖVE game engine. (btw: it is cross-platform, so yes, your funky old XP-laptop will work.)

We’ll also have a presentation by Russ Spivey on build system basics with a focus on TravisCI (since that is what the game uses).

Anyone is welcome to attend this event! No prior experience with open source development or game programming is required.


Monday, April 15th
12:00 PM in Butte 201
Bring your laptop!

Tetris in CoffeeScript

From July 26th through Aug 9th, the team conributed to a Tetris clone written in CoffeeScript: coffee-canvas-tetris

CoffeeScript is unique in that it is compiled into Javascript. Although the syntax is a bit unusual, I found it to be much more concise and easier to read than Javascript. Here is an example of something I contributed to the project:

$(canvas).click -> pause_or_unpause()

The compiled JS looks like this:

$(canvas).click(function() {
  return pause_or_unpause();

So although you’re probably confused about the arrow and dollar sign, I’m sure you can see how much nicer it is to read in CoffeeScript. If you take a look at the project source code, you’ll see just how much of a difference it makes. CoffeeScript was inspired by Ruby and Python, which is why the syntax is so concise.

Beyond just making the code look pretty, CoffeeScript offers a lot of built-in functionality that Javascript lacks. For one, it allows you to define classes, rather than forcing you to use prototypical inheritance. It also offers comprehensions, which are loops but treated as expressions– meaning they can be assigned like a variable.

The most difficult part of this project was setting up the development environment. Just about everyone on the team had difficulties with the dependencies required to run this project. The easiest way (in linux) turned out to be to just download the source and run “sudo bin/cake install” from within the downloaded folder.

My first foray into python

This project had a lot of firsts for me. First time contributing to open source, first time with git, and first time using python.

Along with learning the very basics of python, I was able to expand on PyRunner’s use of the configparser. With it you can quickly create and access sections and variables in a text file.

#If the section does not exist, create it.
config = ConfigParser.ConfigParser()
if not ( config.has_section(score_type) ):
# Creating the needed section.
config.set(score_type,"1", "0")
config.set(score_type,"2", "0")
config.set(score_type,"10", "0")
with open('pyRunner.cfg', 'wb') as configfile:

As you can see, there are convenient functions built in that let you, for example, check for the existence of a section in your file.

And here is what the config file that is generated (and updated in this case) looks like.

10 = 0
1 = 202
3 = 0
2 = 0

The other piece I expanded on was the score keeping system. We wanted to have a top 10 list rather than just the single top score. Here is some recursion I used to do it.

for i in range(1, 11):
if ( int(score) > int(config.get(score_type, str(i))) ):
#store the value I am about to replace
replaced_score = config.get(score_type, str(i))
#replace the value in the list
config.set(score_type, str(i), str(int(score)))
with open('pyRunner.cfg', 'wb') as configfile:
#find the replaced score's new place in the list
#immediatly end the loop when the recursion unwinds

Yes it is simple. But I did learn what happens in python when a recursive function gets away from you. Initially, I forgot to type cast the score variable above leading to this…
RuntimeError: maximum recursion depth exceeded while calling a Python object
Rather than forcing you to kill the process manually, python does it for you and lets you know that it did. Nice.


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):
        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


For our second project (June 14 – 21st), we decided to work on Lovely-snake. This game is a Snake clone written in Lua with the LOVE framework by our teammate Josh. I have always been a huge fan of Snake, so I was excited to work on this project. By the time we got started on it as a team, Josh had already written the basics of the game and had a working demo ready.

One of the things that surprised me about Lua was that it doesn’t have native support for classes, so as the game’s code grew, it became apparent that we’d need to implement classes somehow. We wound up using Middleclass, which works similarly to class systems of other languages, but uses a special class() function to prepare a variable to work as a class:

-- define myClass
myClass = class('myClass')

-- create an instance of myClass
myObject = myClass:new()

Some of the things we worked on were: a scoring system, killing the snake when he hits walls or himself, a scrolling level camera, and a level tile. See our contributions here: https://github.com/jbttn/lovely-snake/pull/13/files

This project still has a lot of TODOs, so if you’d like to contribute, read them here: https://github.com/jbttn/lovely-snake/issues

Josh is working on his own blog post about the level system we worked on, so keep a lookout for that.

Canvasteroids: Our First Project!

At our second meeting on June 7th, we picked our first project: Canvasteroids

Canvasteroids is a Javascript game framework created by David Wilhelm. It includes one example game: Asteroids!

We chose to work on this project because we felt we could make some significant improvements to the example game (plus we needed something easy to get our feet wet). In one week, we added a life and score counter, a hyperspace button, “how to play” guide, thruster animation, and a few other useful things (see all our contributions).

After the week was up, we submitted our changes to the project’s author (via a GitHub pull-request). He merged them in immediately and thanked us, and we got to pat ourselves on the back 🙂

No one on the team had worked on a Javascript game before this project, yet we made a significant contribution to Canvasteroids.

Week one: successful!

[Update: David Wilhem’s made a blog post about our contributions: Updates to Asteroids]