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!
Note: no prior experience is required, but some experience with computer programming is recommended. Bring a laptop with Linux on it!
From July 26th through Aug 9th, the team conributed to a Tetris clone written in CoffeeScript: coffee-canvas-tetris
$(canvas).click -> pause_or_unpause()
The compiled JS looks like this:
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.
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.
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.
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:
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.
At our second meeting on June 7th, we picked our first project: Canvasteroids
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 🙂
Week one: successful!
[Update: David Wilhem’s made a blog post about our contributions: Updates to Asteroids]