Figure 8—Purple Box Monster
- Stop the game if too much fruit gets past the purple fruit monster
- Reset if the game ends
- Incorporate graphics
Although we can add lots more to make the game even better, the core of the
game is done. We can control the avatar. We can tell when the player earns
points. We can tell when the game is over. We can show the score. That’s a
lot of stuff.
Adding Simple Graphics
Of course, we have graphics available for the purple fruit monster, so let’s
add them. First, in the addAvatar() function, make the MeshBasicMaterial invisible
and add the purple fruit monster image:
functionaddAvatar() {
avatar =newPhysijs.BoxMesh(
newTHREE.CubeGeometry(40, 50, 1),
❶ newTHREE.MeshBasicMaterial({visible: false})
);
❷ varavatar_material =newTHREE.MeshBasicMaterial({
map: THREE.ImageUtils.loadTexture('/images/purple_fruit_monster.png'),
transparent: true
});
❸ varavatar_picture =newTHREE.Mesh(
newTHREE.PlaneGeometry(40, 50), avatar_material
);
❹ avatar.add(avatar_picture);
// Everything else stays the same in this function, starting with this:
avatar.position.set(-50, 50, 0);
scene.add(avatar);
report erratum • discuss
Outline the Game • 141
Prepared exclusively for Michael Powell