SNAKE.pdf: the classic you know know and love, now in pdf. Open your chromium based browser of choice and enjoy!
The game itself is (mostly) coded in JavaScript using Adobe's JS API or rather, the small subset of it implemented by chromiumn browsers, although, as explained below, every game element is created with the pdf (which makes it look weird on non-chromium readers).
Controls:
↑ <- Speed ->
← ⏸ →
↓
- Hover your mouse over the arrows on the left to stir the snake
- Click on the middle button to pause/resume game (you may have to click outside and then back inside to resume)
- Hover your mouse over the speed control arrows to make the snake move faster or slower. (does not work while paused)
The embeding of the game inside a pdf file is probably the most interesting aspect of this whole project. It could be done simply by hand (uncompressed unprotected pdf files are actually quite simple) but it would require calculating byte offsets by hand which is, to say the least, a tedious task. Here, it's been done with a python script using the library pdfrw (and a custom module by Omar Rizwan).
A few interesting challenges that arise from the limited API implementation by chromium browsers are:
- Every element of the game is a text box (which means you can pause the game and write just about anything anywhere).
- No new boxes can be created at runtime (though the API), so everything must be created with the file (here done in python).
- The whole game area has to be flashed after moving each text box, otherwise, they would leave a trace like a stamp.
More information can be found in this brilliant post by Omar Rizwan which has been the main source for this project. I encourage the curious reader to go check it out.