September 2018
Intermediate to advanced
328 pages
9h 10m
English
Create a new folder in your /book-examples folder named /chapter-06-interact-with-js. Create a new file in the /chapter-06-interact-with-js folder named js-with-glue.c and populate it with the following contents:
/* * This file interacts with the canvas through imported functions. * It moves a blue rectangle diagonally across the canvas * (mimics the SDL example). */#include <emscripten.h>#include <stdbool.h>#define BOUNDS 255#define RECT_SIDE 50#define BOUNCE_POINT (BOUNDS - RECT_SIDE)bool isRunning = true;typedef struct Rect { int x; int y; char direction;} Rect;struct Rect rect;/* * Updates the rectangle location by 1px in the x and y in a * direction based on its current position. */void updateRectLocation() { // Since we want ...Read now
Unlock full access