The start() function

The updated start() function, which acts as the entry point to the module, is shown as follows:

EMSCRIPTEN_KEEPALIVE
void start(int boundsWidth, int boundsHeight, int rectWidth,
int rectHeight) {
rect.x = 0;
rect.y = 0;
rect.horizDir = 'R';
rect.vertDir = 'D';
rect.width = rectWidth;
rect.height = rectHeight;
bounds.width = boundsWidth;
bounds.height = boundsHeight;
setIsRunning(true);
}

Any functions that are called from JavaScript are prepended with the EMSCRIPTEN_KEEPALIVE statement. We're now passing the width and height of both the Bounds and Rect elements as arguments to the start() function, which we assign to the local bounds and rect variables. This allows us to easily change the dimensions of either one without having to make any changes to the collision detection logic. In the context of this application, the rect represents the rectangle in which the spaceship image resides. We set the default horizontal and vertical direction for the rect so the image initially moves to the right and down. Let's move on to the rect movement/collision detection code.

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

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