functionisWalking() {
if(is_moving_right)returntrue;
if(is_moving_left)returntrue;
if(is_moving_forward)returntrue;
if(is_moving_back)returntrue;
returnfalse;
}
document.addEventListener('keydown',function(event) {
varcode = event.keyCode;
if(code == 37) { // left
marker.position.x = marker.position.x-5;
is_moving_left = true;
}
if(code == 38) { // up
marker.position.z = marker.position.z-5;
is_moving_forward = true;
}
if(code == 39) { // right
marker.position.x = marker.position.x+5;
is_moving_right = true;
}
if(code == 40) { // down
marker.position.z = marker.position.z+5;
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) {
console.log("not left anymore");
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.9 Code: What’s All That Other Code?
There was no new code in Chapter 9, What's All That Other Code?, on page
85. We only explored the code that is automatically created when we start
new projects.
report erratum • discuss
Code: What’s All That Other Code? • 229
Prepared exclusively for Michael Powell