hw7 parts

game log

by chuby0307

HTML

<h1 style="text-align:center"> My first game </h1>
<hr>

<div id="init">User Name:
    <input id="user" type="text" value="Mickey">
    <br/>
    <br/>
    <button id="login">Login</button>
    <p id='greeting'></p>
</div>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
    
</script>

CSS

#info {
    position: absolute;
    top: 0px;
    width: 100%;
    padding: 10px;
    text-align: center;
    color: #ffff00
}
body {
    //overflow: hidden;
}

JavaScript

var camera, scene, renderer, geometry, material, mesh, controls;
var pos, vel;
var clock = new THREE.Clock();
var puck;
var pColor;
var records = [];
var mouse = new THREE.Vector2();
var pucks = [];
var which = 1;


var Puck = function () {
    this.vel = new THREE.Vector3();
    this.pos = new THREE.Vector3();
    this.pColor = new THREE.Color();
    this.mesh = new THREE.Mesh();
    this.pointLight = new THREE.PointLight(0xffffff, 0.3);
};

Puck.prototype.update = function (dt) {
    this.pos.add(this.vel.clone().multiplyScalar(dt));

    this.mesh.position.copy(this.pos);
    this.pointLight.position.set(this.pos.x, 10, this.pos.z);
    this.pointLight.color = this.pColor;
    this.mesh.material.color = this.pColor;

};

Puck.prototype.collision = function () {
    // collision
    if (this.pos.x > 100) {
        this.pos.x = 100;
        this.vel.set(-this.vel.x, 0, this.vel.z);
        this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
    } else if (this.pos.x < -100) {
        this.pos.x = -100;
        this.vel.set(-this.vel.x, 0, this.vel.z);
        this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
    }
    if (this.pos.z > 100) {
        if(this.pos.x<(meshxx.position.x+25) && this.pos.x>(meshxx.position.x-25)){
        this.pos.z = 100;
            this.vel.set(this.vel.x, 0, -this.vel.z);}
        else{this.mesh.visible=false;}
        this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
    } else if (this.pos.z < -100) {
        if(this.pos.x<(meshxx.position.x+25) && this.pos.x>(meshxx.position.x-25)){
        this.pos.z = -100;
            this.vel.set(this.vel.x, 0, -this.vel.z);}
        else{this.mesh.visible=false;}
        this.pColor.setHSL(Math.random(), Math.random(), Math.random() / 2 + 0.5);
    }
}

function newPuck() {
    var puck = new Puck();
    puck.pos = new THREE.Vector3(0, 1, 0);
    puck.vel = new THREE.Vector3(150 * (Math.random() * 2 - 1), 0, 170 *...