Clojure games I have been thinking a lot recently about game programming for a special project of mine. I thought I would use that focus to construct the next issue of the Clojure Gazette.
My intention with this issue is to give a broad introduction to the resources available for writing games in Clojure. Clojure gives you the full power of the JVM and all of the existing libraries, but it presents its own challenges: persistent data structures, the REPL (most Java programs are written to run then exit; many libraries assume this), and in general the functional style.
Game programming can be as simple as implementing an existing game (such as in the Asteroids example). Or it can be an exploration of a complex space of possible rule systems. In the former case, we see that Clojure excels. Take, for example, Conway's Game of Life in Clojure compared with the other languages. The exploratory mode is a challenge in any language, but the REPL should be of assistance here.
In the end, I find game programming in Clojure is quite enjoyable. There is a minimum of boilerplate and I can see the results immediately.
A fun tempest clone written in ClojureScript that runs in your browser. Source code is provided. I used to love this game. Be sure to read the rest of this issue before you start playing because you might not come back.
I've mentioned quil before, but it bares repeating. quil is the Java Processing API wrapped in Clojure. By the way, someone should do the same with ClojureScript. It is under active development.
If you are writing your game in Clojure, you might as well compose the music in Clojure, too. Overtone is an awesome system for musical composition, exploration, and generation. It would probably be useful for sound effects generation as well.
|Jonathan Blow: How and Why (video)|
Jonathan Blow is a well-respected game developer and excellent speaker. In this talk, he focuses more on the why of game development instead of the technical how. He talks about art, creating a game that is worthwhile, and the role of prototyping. Worth a watch even if you are not planning on writing your own games.
JBox2D is a rigid body physics engine written in Java. There is a Clojure wrapper, but it looks like it has not been updated in a long time.
|Purely Functional Retrogames|
A retrospective of the challenges of writing games in a purely functional language (no state change). It includes lots of nuggets of wisdom for game programming or programming any challenge typically solved by mutating state.
|drifting in freespace|
|creating a simple game in clojure|
Zach Tellman explains how he wrote Asteroids in Clojure. It is a good example of breaking down the game into rules and entities. It also explains some of the more interesting details.
|Art Assets for Game Developers|
There are lots of things that need to be done to bootstrap a game from a new Leiningen project to something playable. These resources will give you something to use while you are programming, even if they will eventually be replaced.
|games in the browser|
|HTML5 Canvas Cheat Sheet|
ClojureScript offers the ability to deliver games quickly over the web. This cheat sheet should be most of what you need to get started drawing. Also check out some of the HTML5 games on the same site.