Posted on November 8, 2017 by rodney
Tags: nerd, haskell, games

A long time ago when I was in uni I made a little game for the computer club programming competition. For some reason at that time I enjoyed playing Tetris too much. I wanted to make something like Tetris, but where gravity doesn’t apply. The result was a game where you could drop Tetris pieces on a square board and make lines in both vertical and horizontal directions.

Flatris Game

Flatris Game

It’s moderately amusing but, for fairly obvious reasons, not quite as fun as normal Tetris.

However implementing such a game is always fun! The original was written in C++ with OpenGL. The source code may have been lost. Anyway, I have remade the same game for the web browser using Haskell and Reflex FRP.

You can play it here: https://rvl.github.io/flatris/

I believe FRP (Functional Reactive Programming) is a very powerful abstraction for describing interactive applications such as games and user interfaces.

Reflex is very good but can suffer from the performance issues of running under GHCJS.

It is also sometimes difficult to do particular browser DOM things like getting pixel co-ordinates of mouse events relative to when the mouse button was last pressed (i.e. drag and drop). This is why my Flatris game doesn’t work on mobile phones or small browser windows.

Nevertheless, I would enthusiastically choose Reflex FRP for my next GUI project, if it were possible.

Source code for the game: https://github.com/rvl/flatris