Compiling the physics.html file

Now that we have added physics, it is time to compile our code. We can build the physics.html file with the following em++ command:

em++ asteroid.cpp audio.cpp camera.cpp collider.cpp emitter.cpp enemy_ship.cpp finite_state_machine.cpp locator.cpp main.cpp particle.cpp player_ship.cpp projectile_pool.cpp projectile.cpp range.cpp render_manager.cpp shield.cpp ship.cpp star.cpp vector.cpp -o physics.html --preload-file audio --preload-file sprites -std=c++17 -s USE_WEBGL2=1 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=["png"] -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS=["png"] 

The following screenshot may look similar to earlier versions, but when you fire your projectiles, the ship will accelerate backward. If you collide with an asteroid when your shields are on, you will bounce off them like a billiard ball. Get too close to the sun, and the gravity will begin to attract your ship:

Figure 13.1: physics.html screenshot