3D Game Programming

(C. Jardin) #1
vare_angle = time * 0.001;
earth.position.set(250* Math.cos(e_angle), 250* Math.sin(e_angle), 0);
varm_angle = time * 0.02;
moon_orbit.rotation.set(0, 0, m_angle);
}
animate();

varstars =newTHREE.Geometry();
while(stars.vertices.length < 1e4) {
varlat = Math.PI * Math.random() - Math.PI/2;
varlon = 2*Math.PI * Math.random();

stars.vertices.push(newTHREE.Vector3(
1e5 * Math.cos(lon) * Math.cos(lat),
1e5 * Math.sin(lon) * Math.cos(lat),
1e5 * Math.sin(lat)
));
}
varstar_stuff =newTHREE.ParticleBasicMaterial({size: 500});
varstar_system =newTHREE.ParticleSystem(stars, star_stuff);
scene.add(star_system);

document.addEventListener("keydown",function(event) {
varcode = event.keyCode;

if(code == 67) changeCamera();// C
if(code == 32) changeCamera();// space
if(code == 80) pause = !pause;// P
if(code == 49) speed = 1;// 1
if(code == 50) speed = 2;// 2
if(code == 51) speed = 10;// 3
});

functionchangeCamera() {
if(camera == above_cam) camera = earth_cam;
elsecamera = above_cam;
}
</script>

A1.15Code: The Purple Fruit Monster Game


This is the final version of the game code from Chapter 15, Project: The Purple
Fruit Monster Game, on page 133.

<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/physi.js"></script>
<script src="http://gamingJS.com/Scoreboard.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script>
// This is where stuff in our game will happen:

report erratum • discuss

Code: The Purple Fruit Monster Game • 245


Prepared exclusively for Michael Powell

Free download pdf