Game
by 蔡 育曄
HTML
<div id="info">Hexagon Base</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/94/three.min.js"></script>
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://rawgit.com/jyunming-chen/tutsplus/master/js/text2D.js"></script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden
}
JavaScript
var mGrids = [];
var N = 4;
const SIZE = 10;
const SQRT3 = Math.sqrt(3);
var score = 0,scoreB = 0;
var gameoverA,gameoverB;
var baseA,baseB;
var planeA,planeB;
var m,mB;
var j,k,s,t;
var ball,lacA,lacB;
var pickplane;
var first_row = -N; // the 'r' of first row
function first_column(r) { // the first column at r = 'r'
if (r < 0)
return -(N + r);
else
return -N;
}
class Ball {
constructor (mass = 1, radius=38/Math.PI, friction = 0) {
this.type = 'ball';
this.mass = mass; // may need to differentiate basketball & bowling ball
this.radius = radius;
this.friction = friction; // for contact
// for dynamics calculation
this.pos = new THREE.Vector3();
this.vel = new THREE.Vector3();
this.initV = new THREE.Vector3();
this.force = new THREE.Vector3();
this.count = 0;
this.obj = new THREE.Object3D();
loader.setCrossOrigin ('');
let mesh = new THREE.Mesh (new THREE.SphereGeometry(radius, 32, 32), new THREE.MeshLambertMaterial({map:loader.load("https://i.imgur.com/Sw4OGXN.png")}))
this.obj.add (mesh)
scene.add (this.obj)
}
update(dt) {
// after GLOBAL collision & contact
this.vel.add (this.force.clone().multiplyScalar(dt))
this.pos.add (this.vel.clone().multiplyScalar(dt))
this.obj.position.copy (this.pos);
if(this.obj.position.y <this.radius) {
bump();
// this.pos.copy(baseB.position.clone().add(new THREE.Vector3(0,shell.radius/2+5,0)));
// this.vel.copy(shell.initV);
//this.obj.position.copy(this.pos)
update = !update;
console.log(update)
}
}
// useless API
moveTo(thePos) {
this.pos.copy (thePos);
this.obj.position.copy (this.pos);
}
rotateTo (theta) { // abs CCW angle
this.obj.rotation.z = theta;
//this.normal.applyEuler (new THREE.Euler (0,0,theta))
}
}
class Cube { // cube coordinate
constructor(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
toHex() {
var q =...