Mashed Games is the result of a discussion of three colleagues about bit operations.
About two years ago when Peter Molyneux’s Curiosity Cube hit the media we were curious too and found the idea pretty interesting. Unfortunately, the first days Curiosity was down a couple of times due to the media coverage and the number of people trying to play it. So we started wondering: What might be the bottleneck there?
We came to the conclusion that it’s probably caused by the number of connections and the updating service which has to keep track of the cube’s tiles and broadcast the updates.
Next thing that came to our minds was: What would we do, if we had to store a huge tilemap?
Storing a huge tilemap in an array or even a database with geospacial indexing sounded like a huge waste of ressources to us. We believed the solution had to be simpler. A single byte could store the state of 8 tiles (set/unset) and tiles could be unset with a few bit operations. So the logical consequence for us was to store everything binary and set/unset single bits with bit operations. The number of tiles per axis just had to be a multiple of 8. This way a tilemap could be easily stored in a single file. To prove our idea could work, we hacked a few scripts together and a bit later we had a simple web interface which displayed a map of 64×64 tiles in ASCII characters. The file on disk was just 512bytes. By clicking on a tile, we calculated the offset of the byte, unset the according bit on the server and broadcasted the change to all connected clients.
That was already pretty cool but we weren’t satisfied. Now that we had the proof-of-concept working we wanted to make more out of it and created a game: Mashed Games.
The goal of this game is to destroy the entire map and the player who destroys the last tile wins! To make it more fun, we added a few characters from games we loved in our youth. The characters can be unlocked while progressing on the map.
The clients connect to a couple of processes which use SailsJs to provide the REST and WebSocket endpoints. Each of the sails processes connects to our map master to pass the deleted tiles and the map master broadcasts the changes periodically to all connected clients (socket.io + redis pub/sub interface). To keep the amount of data in transfer small, we split the map into chunks of 256×256 bits each. A player only receives updates for the chunks that are visible on his screen. To achieve that, we created one socket.io room per chunk and while the player moves on the map, we make him join&leave these rooms in the background.
Now you might wonder: That was two years ago? Did you really take that long for a simple game?
No, it acutually didn’t take us two years to write this game, but as Paul Dix put it on HN the other day: “In software development there a lies, damn lies and timeline estimates”. We simply lost the motivation over christmas 2012 and totally forgot it until a few weeks ago. The game was already working back in 2012 and only needed some more polishing, some bugfixes and a few more features to make it even more fun. It would have been a shame if we didn’t finish it, especially since it was a lot of fun writing it. Eventually we finished it and are really happy with the result.
Now there’s only one question left:
Did we make it better or would we suffer from the same issues the Curiosity Cube had, when it went viral?
We don’t know yet, but we are eager to find out. So please spread the word!
We hope you enjoy playing this game, as much as we enjoyed coding it.