
Thomas Rinsma decided to abuse PDF field objects to render monochrome grid, and combine it with keystroke-entry in a text field to receive inputs – that’s how playable Tetris in a PDF file was born.
You can read the blog post about the implementation details from the author himself – the display part is quite interesting:
For Tetris, I just created a 10×20 grid of buttons (they can be styled however you want), which can be shown/hidden from JavaScript by setting their .hidden property, creating monochrome pixels.
var pixel_fields = []; function game_init() { // Gather references to pixel field objects for (var x = 0; x < 10; ++x) { pixel_fields[x] = []; for (var y = 0; y < 20; ++y) { pixel_fields[x][y] = this.getField(`P_${x}_${y}`); } } // ... } function set_pixel(x, y, state) { // ... pixel_fields[x][20 - 1 - y].hidden = !state; }
The game itself is called PDFTris, and the sources are available on GitHub. Keep in mind the game works in PDF.js (Firefox) and PDFium (Chromium-based browsers) - other engines were not tested.
Can it run DOOM?
If you can play Tetris in a PDF, then you should also be able to play DOOM, right? Yes, of course! The PDFDOOM is a thing, and the sources are on GitHub as well.
HTML5 Game Developer, Enclave Games indie studio founder, js13kGames competition creator and Gamedev.js Weekly newsletter publisher. Mozilla Tech Speaker, Gamedev.js community firestarter. Organizes meetups / workshops / hackathons in Poland, passionate about new, Open Web technologies, excited about WebXR and PWAs. Likes eating sushi and playing Neuroshima Hex.