Setting the Game’s Boundaries

All of the action in this game will take place on the screen. So we need something to keep the avatar in the screen. We need boundaries—four of them. Since we need to add four of the same things, we’ll do so with a makeBorder function. This function will use x and y positions to decide where to place the border. It will also define a width and height to build the correct shape. Let’s add the following code to our project below the START CODING line:

 
function​ makeBorder(x, y, w, h) {
 
var​ border = ​new​ Physijs.BoxMesh(
 
new​ THREE.CubeGeometry(w, h, 100),
 
Physijs.createMaterial(
 
new​ THREE.MeshBasicMaterial({color: 0x000000}), 0.2, 1.0
 
),
 
0
 
);
 
border.position.set(x, y, 0);
 
return​ border; ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.