GameProgramming HW3 Demo
with orbitControls, XZgrid, info
by Alan Lin
HTML
<div id="info">GameProgramming HW3 Demo
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>
<audio id="BGM" autoplay loop style="display:none">
<source src="http://alan0917.github.io/hw/sounds/The Truth That You Leave.mp3" type='audio/mp3'>
</audio>
<audio id="SE" style="display:none">
<source src="http://alan0917.github.io/hw/sounds/彈簧聲.wav" type='audio/wav'>
</audio>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ff00ff
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer;
var satellite, angle = 0;
var mousePoint;
var mouse = new THREE.Vector2();
//var stats;
var pos, vel, force;
var clock = new THREE.Clock();
var keyboard = new KeyboardState();
var ball;
var planeP = new THREE.Vector3(10, 0, 0);
var planeN = new THREE.Vector3(0, 1, 0);
var JUMP = true, JUMP2 = true;
var ballR = 3;
var soundVal = 1.0, sign = 1.0;
var BGM, SE;
var stArray = [], baseS = 0, counter = 0;
var ground = new Array();
init();
animate();
function setUpStArray() {
for (var i = 0; i < 3; i++) {
var row = [];
for (var j = 0; j < 9; j++)
row.push(new THREE.Vector2(j * 0.125, 1 - 0.5 * i));
stArray.push(row);
}
}
var Ground = function(mesh,width,height,pos){
this.mesh = mesh;
this.width = width;
this.height = height;
this.pos = pos;
this.mesh.geometry.computeFaceNormals();
this.normal = new THREE.Vector3(0,1,0).normalize();
}
function init() {
SE = document.getElementById ('SE');
BGM = document.getElementById ('BGM');
renderer = new THREE.WebGLRenderer({
antialias: true
});
pos = new THREE.Vector3(-20, 40, 1);
vel = new THREE.Vector3(5, 0, 0);
//force = new THREE.Vector3(0, -90, 0);
/*
// STATS
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
stats.domElement.style.zIndex = 100;
document.body.appendChild( stats.domElement );
*/
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x888888);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.OrthographicCamera(-50, 50, 60, -10, -10, 100);
camera.position.z = 0;
scene.add(camera);
THREE.ImageUtils.crossOrigin = '';
var texture = THREE.ImageUtils.loadTexture('http://i.imgur.com/qNL5upu.png');
for (var i = 0; i < 5; i++){
var background = new THREE.Mesh (new THREE.PlaneGeometry (150,80), new THREE.MeshBasicMaterial({map:texture}));
background.position.y...