Earlier this month, Henrik Nilsson & Ivan Perez presented a tutorial at PPDP 14 on Declarative Game Programming.

The goal was to show how real game programming is possible in a purely functional, declarative way. One way of doing so, seeing games as networks of interconnected signals and signal transformers, results in clear, reusable, modular code.

To illustrate these ideas, a small but realistic game was demonstrated, featuring many of the complex elements found in arcade games: SDL graphics and sound, Wiimote controller, and differentiated subsystems for rendering and sound, game input, physics/collisions, game logic, etc. The game has several levels, each with its own background and music.

To help others interested in functional game programming, all the talk material have been made available, including the slides and the full game code.

Slides: http://www.cs.nott.ac.uk/~nhn/frp-yampa-tutorials.html

Game code: http://github.com/ivanperez-keera/haskanoid

Hackage Package: http://hackage.haskell.org/package/haskanoid

UNotts announcement: http://fplab.bitbucket.org/posts/2014-09-23-declarative-game-programm.html (broken as of June 2017)

You are encouraged to go through the code, point out any issues/questions you may have, suggest improvements and even send pull requests. The code features a lot of documentation. Hackage won’t generate it for you, but you can with haddock (see readme file on github for details).

We are working on an full Android version of this game (with levels, enemies, and a lot of other stuff). But don’t take our word for it: below is a video of an early version of the Haskell code, already running on a Galaxy Tab 2:

To answer a question posted during the talk: the code is being compiled to native code using the GHC backend for android (which generates ARM object code). Upon loading the game, a Java wrapper calls a C wrapper that initialises the runtime system and calls Haskell. This takes less than half a second. For the rest of the game, it’s object running directly on the tablet.

You’ll notice that there are small glitches and delays, and the speed and frames per second are low (something we wrote about last month, when we announced Haskell games for Android). Recent (unpublished) improvements have made the FPS go trough the roof on desktop, and to more-than-playable levels on tablet. We’ll be sharing videos and stats on our next post.

Keera Studios on Facebook: https://www.facebook.com/keerastudios

Keera Studios on Twitter: https://twitter.com/KeeraStudios

Keera Studios on Github: https://github.com/keera-studios

Many thanks to those who flattred our last publication. These small donations are dedicated in full to our game, and they mean the world to us. Please, spread the word!

EDIT: Linked Henrik Nilsson’s page for the papers instead of the PDFs directly.