scene.add(makeBorder(width/-2, 0, 50, height));
scene.add(makeBorder(width/2, 0, 50, height));
scene.add(makeBorder(0, height/2, width, 50));
scene.add(makeBorder(0, height/-2, width, 50));
varavatar =newPhysijs.ConvexMesh(
newTHREE.CylinderGeometry(30, 30, 5, 16),
Physijs.createMaterial(
newTHREE.MeshBasicMaterial({color:0xbb0000}), 0.2, 0.5
)
);
avatar.rotation.set(Math.PI/2, 0, 0);
avatar.position.set(0.5 * width/-2, -height/2 + 25 + 30, 0);
scene.add(avatar);
avatar.setAngularFactor(newTHREE.Vector3( 0, 0, 0 ));// don't rotate
avatar.setLinearFactor(newTHREE.Vector3( 1, 1, 0 )); // only move on X and Y axis
document.addEventListener("keydown",function(event) {
varcode = event.keyCode;
if(code == 37) move(-50);// left arrow
if(code == 39) move(50); // right arrow
});
functionmove(x) {
varv_y = avatar.getLinearVelocity().y,
v_x = avatar.getLinearVelocity().x;
if(Math.abs(v_x + x) > 200)return;
avatar.setLinearVelocity(
newTHREE.Vector3(v_x + x, v_y, 0)
);
}
vargoal =newPhysijs.ConvexMesh(
newTHREE.TorusGeometry(100, 25, 20, 30),
Physijs.createMaterial(
newTHREE.MeshBasicMaterial({color:0x00bb00})
),
0
);
goal.isGoal = true;
functionplaceGoal() {
varx = 0,
rand = Math.random();
if(rand < 0.33) x = width / -2;
if(rand > 0.66) x = width / 2;
goal.position.set(x, height/2, 0);
scene.add(goal);
report erratum • discuss
Code: Multilevel Game • 261
Prepared exclusively for Michael Powell