Update index.html
Browse files- index.html +45 -36
index.html
CHANGED
@@ -26,71 +26,81 @@
|
|
26 |
|
27 |
var ballGeometry = new THREE.SphereGeometry(0.5, 32, 32);
|
28 |
var ballMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
29 |
-
var
|
30 |
-
scene.add(ball);
|
31 |
-
|
32 |
-
var paddleGeometry = new THREE.BoxGeometry(4, 1, 1);
|
33 |
-
var paddleMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
34 |
-
var paddle = new THREE.Mesh(paddleGeometry, paddleMaterial);
|
35 |
-
paddle.position.y = -15;
|
36 |
-
scene.add(paddle);
|
37 |
|
38 |
var brickGeometry = new THREE.BoxGeometry(2, 1, 1);
|
39 |
var bricks = [];
|
40 |
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
var brickMaterial = new THREE.MeshLambertMaterial({ color: Math.random() * 0xffffff });
|
43 |
var brick = new THREE.Mesh(brickGeometry, brickMaterial);
|
44 |
-
brick.position.
|
45 |
-
brick.position.y = (Math.random() - 0.5) * 50;
|
46 |
-
brick.position.z = (Math.random() - 0.5) * 50;
|
47 |
scene.add(brick);
|
48 |
bricks.push(brick);
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
51 |
var light = new THREE.PointLight(0xffffff, 1, 100);
|
52 |
light.position.set(0, 30, 0);
|
53 |
scene.add(light);
|
54 |
|
55 |
var speed = 0.1;
|
56 |
-
var xSpeed = speed;
|
57 |
-
var ySpeed = speed;
|
58 |
-
var zSpeed = speed;
|
59 |
|
60 |
function animate() {
|
61 |
requestAnimationFrame(animate);
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
}
|
74 |
|
75 |
-
if (
|
76 |
-
|
77 |
}
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
bricks.splice(i, 1);
|
87 |
-
ySpeed = -ySpeed;
|
88 |
}
|
89 |
}
|
90 |
|
91 |
renderer.render(scene, camera);
|
92 |
}
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
document.addEventListener('keydown', function(event) {
|
95 |
if (event.keyCode === 37) {
|
96 |
paddle.position.x -= 1;
|
@@ -108,6 +118,5 @@ ySpeed = -ySpeed;
|
|
108 |
|
109 |
animate();
|
110 |
</script>
|
111 |
-
|
112 |
-
</body>
|
113 |
</html>
|
|
|
26 |
|
27 |
var ballGeometry = new THREE.SphereGeometry(0.5, 32, 32);
|
28 |
var ballMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
29 |
+
var balls = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
var brickGeometry = new THREE.BoxGeometry(2, 1, 1);
|
32 |
var bricks = [];
|
33 |
|
34 |
+
function addBall() {
|
35 |
+
var ball = new THREE.Mesh(ballGeometry, ballMaterial);
|
36 |
+
ball.position.set((Math.random() - 0.5) * 25, (Math.random() - 0.5) * 25, (Math.random() - 0.5) * 25);
|
37 |
+
scene.add(ball);
|
38 |
+
balls.push(ball);
|
39 |
+
}
|
40 |
+
|
41 |
+
function addBrick() {
|
42 |
var brickMaterial = new THREE.MeshLambertMaterial({ color: Math.random() * 0xffffff });
|
43 |
var brick = new THREE.Mesh(brickGeometry, brickMaterial);
|
44 |
+
brick.position.set((Math.random() - 0.5) * 50, (Math.random() - 0.5) * 50, (Math.random() - 0.5) * 50);
|
|
|
|
|
45 |
scene.add(brick);
|
46 |
bricks.push(brick);
|
47 |
}
|
48 |
|
49 |
+
for (var i = 0; i < 50; i++) {
|
50 |
+
addBrick();
|
51 |
+
}
|
52 |
+
|
53 |
var light = new THREE.PointLight(0xffffff, 1, 100);
|
54 |
light.position.set(0, 30, 0);
|
55 |
scene.add(light);
|
56 |
|
57 |
var speed = 0.1;
|
|
|
|
|
|
|
58 |
|
59 |
function animate() {
|
60 |
requestAnimationFrame(animate);
|
61 |
|
62 |
+
for (var i = 0; i < balls.length; i++) {
|
63 |
+
balls[i].position.x += (Math.random() - 0.5) * speed;
|
64 |
+
balls[i].position.y += (Math.random() - 0.5) * speed;
|
65 |
+
balls[i].position.z += (Math.random() - 0.5) * speed;
|
66 |
|
67 |
+
if (balls[i].position.x + 0.5 > 25 || balls[i].position.x - 0.5 < -25) {
|
68 |
+
balls[i].position.x = balls[i].position.x > 0 ? 25 - 0.5 : -25 + 0.5;
|
69 |
+
}
|
70 |
|
71 |
+
if (balls[i].position.y + 0.5 > 25 || balls[i].position.y - 0.5 < -25) {
|
72 |
+
balls[i].position.y = balls[i].position.y > 0 ? 25 - 0.5 : -25 + 0.5;
|
73 |
+
}
|
74 |
+
if (balls[i].position.z + 0.5 > 25 || balls[i].position.z - 0.5 < -25) {
|
75 |
+
balls[i].position.z = balls[i].position.z > 0 ? 25 - 0.5 : -25 + 0.5;
|
76 |
}
|
77 |
|
78 |
+
if (balls[i].position.y - 0.5 < -15 && balls[i].position.x + 0.5 > paddle.position.x - 2 && balls[i].position.x - 0.5 < paddle.position.x + 2 && balls[i].position.z + 0.5 > paddle.position.z - 0.5 && balls[i].position.z - 0.5 < paddle.position.z + 0.5) {
|
79 |
+
balls[i].position.y = -15 + 0.5;
|
80 |
}
|
81 |
|
82 |
+
for (var j = 0; j < bricks.length; j++) {
|
83 |
+
if (balls[i].position.y + 0.5 > bricks[j].position.y - 0.5 && balls[i].position.y - 0.5 < bricks[j].position.y + 0.5 && balls[i].position.x + 0.5 > bricks[j].position.x - 1 && balls[i].position.x - 0.5 < bricks[j].position.x + 1 && balls[i].position.z + 0.5 > bricks[j].position.z - 0.5 && balls[i].position.z - 0.5 < bricks[j].position.z + 0.5) {
|
84 |
+
scene.remove(bricks[j]);
|
85 |
+
bricks.splice(j, 1);
|
86 |
+
balls[i].position.y = balls[i].position.y > 0 ? 25 - 0.5 : -25 + 0.5;
|
87 |
+
addBrick();
|
88 |
+
}
|
|
|
|
|
89 |
}
|
90 |
}
|
91 |
|
92 |
renderer.render(scene, camera);
|
93 |
}
|
94 |
|
95 |
+
document.addEventListener('mousedown', function(event) {
|
96 |
+
if (event.button === 0) {
|
97 |
+
addBrick();
|
98 |
+
}
|
99 |
+
if (event.button === 2) {
|
100 |
+
addBall();
|
101 |
+
}
|
102 |
+
});
|
103 |
+
|
104 |
document.addEventListener('keydown', function(event) {
|
105 |
if (event.keyCode === 37) {
|
106 |
paddle.position.x -= 1;
|
|
|
118 |
|
119 |
animate();
|
120 |
</script>
|
121 |
+
</body>
|
|
|
122 |
</html>
|