Update index.html
Browse files- index.html +106 -108
index.html
CHANGED
|
@@ -1,111 +1,109 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
</a-scene>
|
| 110 |
-
</body>
|
| 111 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>3D Breakout Game</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { margin: 0; }
|
| 8 |
+
canvas { width: 100%; height: 100%; }
|
| 9 |
+
</style>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
|
| 11 |
+
</head>
|
| 12 |
+
<body>
|
| 13 |
+
<canvas id="gameCanvas"></canvas>
|
| 14 |
+
|
| 15 |
+
<script>
|
| 16 |
+
var scene = new THREE.Scene();
|
| 17 |
+
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
| 18 |
+
camera.position.z = 5;
|
| 19 |
+
scene.add(camera);
|
| 20 |
+
|
| 21 |
+
var renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gameCanvas') });
|
| 22 |
+
renderer.setClearColor(0x000000);
|
| 23 |
+
renderer.setPixelRatio(window.devicePixelRatio);
|
| 24 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
| 25 |
+
|
| 26 |
+
var ballGeometry = new THREE.SphereGeometry(0.5, 32, 32);
|
| 27 |
+
var ballMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
| 28 |
+
var ball = new THREE.Mesh(ballGeometry, ballMaterial);
|
| 29 |
+
scene.add(ball);
|
| 30 |
+
|
| 31 |
+
var paddleGeometry = new THREE.BoxGeometry(4, 1, 1);
|
| 32 |
+
var paddleMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
| 33 |
+
var paddle = new THREE.Mesh(paddleGeometry, paddleMaterial);
|
| 34 |
+
paddle.position.y = -3;
|
| 35 |
+
scene.add(paddle);
|
| 36 |
+
|
| 37 |
+
var brickGeometry = new THREE.BoxGeometry(2, 1, 1);
|
| 38 |
+
var brickMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
| 39 |
+
var bricks = [];
|
| 40 |
+
|
| 41 |
+
for (var i = 0; i < 5; i++) {
|
| 42 |
+
for (var j = 0; j < 6; j++) {
|
| 43 |
+
var brick = new THREE.Mesh(brickGeometry, brickMaterial);
|
| 44 |
+
brick.position.x = j * 3 - 7;
|
| 45 |
+
brick.position.y = i * 2 + 3;
|
| 46 |
+
scene.add(brick);
|
| 47 |
+
bricks.push(brick);
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
var light = new THREE.PointLight(0xffffff, 1, 100);
|
| 52 |
+
light.position.set(0, 0, 10);
|
| 53 |
+
scene.add(light);
|
| 54 |
+
|
| 55 |
+
var speed = 0.05;
|
| 56 |
+
var xSpeed = speed;
|
| 57 |
+
var ySpeed = speed;
|
| 58 |
+
|
| 59 |
+
function animate() {
|
| 60 |
+
requestAnimationFrame(animate);
|
| 61 |
+
|
| 62 |
+
ball.position.x += xSpeed;
|
| 63 |
+
ball.position.y += ySpeed;
|
| 64 |
+
|
| 65 |
+
if (ball.position.x + 0.5 > 10 || ball.position.x - 0.5 < -10) {
|
| 66 |
+
xSpeed = -xSpeed;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
if (ball.position.y + 0.5 > 10) {
|
| 70 |
+
ySpeed = -ySpeed;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
if (ball.position.y - 0.5 < -4) {
|
| 74 |
+
alert('Game Over!');
|
| 75 |
+
location.reload();
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (ball.position.y - 0.5 < paddle.position.y + 0.5 && ball.position.x + 0.5 > paddle.position.x - 2 && ball.position.x - 0.5 < paddle.position.x + 2) {
|
| 79 |
+
ySpeed = -ySpeed;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
for (var i = 0; i < bricks.length; i++) {
|
| 83 |
+
if (ball.position.y + 0.5 > bricks[i].position.y - 0.5 && ball.position.y - 0.5 < bricks[i].position.y + 0.5 && ball.position.x + 0.5 > bricks[i].position.x - 1 && ball.position.x - 0.5 < bricks[i].position.x + 1) {
|
| 84 |
+
scene.remove(bricks[i]);
|
| 85 |
+
bricks.splice(i, 1);
|
| 86 |
+
ySpeed = -ySpeed;
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
if (bricks.length === 0) {
|
| 90 |
+
alert('You win!');
|
| 91 |
+
location.reload();
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
renderer.render(scene, camera);
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
document.addEventListener('keydown', function(event) {
|
| 98 |
+
if (event.keyCode === 37) {
|
| 99 |
+
paddle.position.x -= 0.5;
|
| 100 |
+
}
|
| 101 |
+
if (event.keyCode === 39) {
|
| 102 |
+
paddle.position.x += 0.5;
|
| 103 |
+
}
|
| 104 |
+
});
|
| 105 |
+
|
| 106 |
+
animate();
|
| 107 |
+
</script>
|
| 108 |
+
</body>
|
|
|
|
|
|
|
| 109 |
</html>
|