Overview of the game
In this chapter, we're taking a Tetris clone written in C++ and updating the code to integrate Emscripten and compile to Wasm/JS. The code base in its original form compiled to an executable utilizes SDL2 and can be loaded from the command line. In this section, we're going to briefly review what Tetris is, how to get the code (without having to write it from scratch), and how to get it running.
Â
What is Tetris?
In Tetris, the main objective of the game is to rotate and move pieces (Tetriminos) of various shapes within a playing field (well or matrix) to create a row of blocks without gaps. When a full row is created, it is deleted from the playing field and your score is increased by one. In our version of the game, there won't be a win condition (although it would be simple to add it).
It's important to understand the rules and mechanics of the game because the code uses algorithms for concepts such as collision detection and scoring. Understanding the goal of a function...