This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setup() | |
{ | |
draw(); | |
} | |
function draw() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------------------------------- | |
// Based on Aerotwist's cool tutorial - http://www.aerotwist.com/tutorials/getting-started-with-three-js/ | |
// --------------------------------- | |
// set up the sphere vars | |
// lower 'segment' and 'ring' values will increase performance | |
var radius = 5, | |
segments = 6, | |
rings = 6; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set up the paddle vars | |
paddleWidth = 10; | |
paddleHeight = 30; | |
paddleDepth = 10; | |
paddleQuality = 1; | |
// set up paddle 1 | |
paddle1 = new THREE.Mesh( | |
new THREE.CubeGeometry( | |
paddleWidth, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
camera = new THREE.PerspectiveCamera( | |
VIEW_ANGLE, | |
ASPECT, | |
NEAR, | |
FAR); | |
scene = new THREE.Scene(); | |
// add the camera to the scene | |
scene.add(camera); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create the plane's material | |
var planeMaterial = | |
new THREE.MeshLambertMaterial( | |
{ | |
color: 0x4BD121 | |
}); | |
// create the playing surface plane | |
var plane = new THREE.Mesh( | |
new THREE.PlaneGeometry( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// // create a point light | |
pointLight = new THREE.PointLight(0xF8D898); | |
// set its position | |
pointLight.position.x = -1000; | |
pointLight.position.y = 0; | |
pointLight.position.z = 1000; | |
pointLight.intensity = 2.9; | |
pointLight.distance = 10000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ball's x-direction, y-direction and speed per frame | |
var ballDirX = 1, ballDirY = 1, ballSpeed = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// update ball position over time | |
ball.position.x += ballDirX * ballSpeed; | |
ball.position.y += ballDirY * ballSpeed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if ball goes off the top side (side of table) | |
if (ball.position.y <= -fieldHeight/2) | |
{ | |
ballDirY = -ballDirY; | |
} | |
// if ball goes off the bottom side (side of table) | |
if (ball.position.y >= fieldHeight/2) | |
{ | |
ballDirY = -ballDirY; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// update the board to reflect the max score for match win | |
document.getElementById("winnerBoard").innerHTML = "First to " + maxScore + " wins!"; |
NewerOlder