Running the game

Instead of using serve or browser-sync, we're going to use a built-in feature of Emscripten's toolchain, emrun. It provides the added benefit of capturing stdout and stderr (if you pass the --emrun linker flag to the emcc command) and printing them to the terminal if desired. We're not going to use the --emrun flag, but having a local web server available without having to install any additional dependencies is a nice added feature to be aware of. Open up a terminal instance within your project folder and run the following command to start the game:

emrun --browser chrome --no_emrun_detect public/index.html

You can specify firefox for the browser if that's what you're using for development. The --no_emrun_detect flag hides a message in the terminal stating that the HTML page is not emrun capable. If you navigate to http://localhost:6931/index.html, you should see the following:

Tetris running in the browser

Try rotating and moving the pieces to ensure that everything is working correctly. The ROWS count should increment by one when you've successfully cleared a row. You may also notice that if you're too close to the edge of the board, you won't be able to rotate some of the pieces. Congratulations, you've successfully ported a C++ game over to Emscripten!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset