3D Game Programming

(C. Jardin) #1
is_moving_back = true;
}
if(code == 67) is_cartwheeling = !is_cartwheeling;// C
if(code == 70) is_flipping = !is_flipping; // F
});

document.addEventListener('keyup',function(event) {
varcode = event.keyCode;

if(code == 37) is_moving_left = false;
if(code == 38) is_moving_forward = false;
if(code == 39) is_moving_right = false;
if(code == 40) is_moving_back = false;
});
</script>

A1.7 Code: A Closer Look at JavaScript Fundamentals


There was no project code in Chapter 7, A Closer Look at JavaScript Funda-
mentals, on page 67.

A1.8 Code: Turning Our Avatar


This is the code from Chapter 8, Project: Turning Our Avatar, on page 79.


<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/Tween.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<body></body><script>
// This is where stuff in our game will happen:
varscene =newTHREE.Scene();

// This is what sees the stuff:
varaspect_ratio = window.innerWidth / window.innerHeight;
varcamera =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);
camera.position.z = 500;
//scene.add(camera);

// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.CanvasRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// ******** START CODING ON THE NEXT LINE ********
varmarker =newTHREE.Object3D();
scene.add(marker);

varcover =newTHREE.MeshNormalMaterial();
varbody =newTHREE.SphereGeometry(100);
varavatar =newTHREE.Mesh(body, cover);

Appendix 1. Project Code • 226


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf