Update index.html
Browse files- index.html +14 -195
index.html
CHANGED
@@ -1,202 +1,21 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
-
|
5 |
-
<title>🤓🕹️📱 3D Breakout Game</title>
|
6 |
-
<style>
|
7 |
-
body {
|
8 |
-
margin: 0;
|
9 |
-
}
|
10 |
-
|
11 |
-
canvas {
|
12 |
-
width: 100%;
|
13 |
-
height: 100%;
|
14 |
-
}
|
15 |
-
|
16 |
-
#score {
|
17 |
-
position: absolute;
|
18 |
-
top: 0;
|
19 |
-
left: 50%;
|
20 |
-
transform: translateX(-50%);
|
21 |
-
font-size: 24px;
|
22 |
-
font-weight: bold;
|
23 |
-
color: white;
|
24 |
-
text-shadow: 1px 1px 1px black;
|
25 |
-
}
|
26 |
-
</style>
|
27 |
-
<script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script>
|
28 |
</head>
|
29 |
<body>
|
30 |
-
|
31 |
-
<
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
createGeometry();
|
44 |
-
for (var i = 0; i < 50; i++) {
|
45 |
-
addBall();
|
46 |
-
}
|
47 |
-
|
48 |
-
// Adding bricks
|
49 |
-
for (var i = 0; i < 50; i++) {
|
50 |
-
addBrick();
|
51 |
-
}
|
52 |
-
|
53 |
-
// Adding light
|
54 |
-
addLight();
|
55 |
-
|
56 |
-
// Adding paddle
|
57 |
-
addPaddle();
|
58 |
-
|
59 |
-
// Registering event listeners
|
60 |
-
registerEvents();
|
61 |
-
|
62 |
-
// Fetching data for 3D letters
|
63 |
-
fetchLetters();
|
64 |
-
|
65 |
-
// Starting animation
|
66 |
-
animate();
|
67 |
-
|
68 |
-
function setupScene() {
|
69 |
-
scene = new THREE.Scene();
|
70 |
-
camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
71 |
-
camera.position.set(0, 30, 0);
|
72 |
-
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
73 |
-
scene.add(camera);
|
74 |
-
}
|
75 |
-
|
76 |
-
function setupRenderer() {
|
77 |
-
renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gameCanvas') });
|
78 |
-
renderer.setClearColor(0x000000);
|
79 |
-
renderer.setPixelRatio(window.devicePixelRatio);
|
80 |
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
81 |
-
}
|
82 |
-
|
83 |
-
function createGeometry() {
|
84 |
-
ballGeometry = new THREE.SphereGeometry(0.5, 32, 32);
|
85 |
-
ballMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
86 |
-
brickGeometry = new THREE.BoxGeometry(2, 1, 1);
|
87 |
-
}
|
88 |
-
|
89 |
-
function addBall() {
|
90 |
-
var ball = createMesh(ballGeometry, ballMaterial);
|
91 |
-
ball.velocity = getRandomVelocity();
|
92 |
-
balls.push(ball);
|
93 |
-
}
|
94 |
-
|
95 |
-
function addBrick() {
|
96 |
-
var brickMaterial = new THREE.MeshLambertMaterial({ color: Math.random() * 0xffffff });
|
97 |
-
var brick = createMesh(brickGeometry, brickMaterial);
|
98 |
-
bricks.push(brick);
|
99 |
-
}
|
100 |
-
|
101 |
-
function addLight() {
|
102 |
-
light = new THREE.PointLight(0xffffff, 1, 100);
|
103 |
-
light.position.set(0, 30, 0);
|
104 |
-
scene.add(light);
|
105 |
-
}
|
106 |
-
|
107 |
-
function addPaddle() {
|
108 |
-
paddleGeometry = new THREE.BoxGeometry(4, 1, 1);
|
109 |
-
paddleMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
110 |
-
paddle = createMesh(paddleGeometry, paddleMaterial);
|
111 |
-
}
|
112 |
-
|
113 |
-
function createMesh(geometry, material) {
|
114 |
-
var mesh = new THREE.Mesh(geometry, material);
|
115 |
-
mesh.position.set(getRandomPosition());
|
116 |
-
scene.add(mesh);
|
117 |
-
return mesh;
|
118 |
-
}
|
119 |
-
|
120 |
-
function getRandomPosition() {
|
121 |
-
return new THREE.Vector3((Math.random() - 0.5) * 50, (Math.random() - 0.5) * 50, (Math.random() - 0.5) * 50);
|
122 |
-
}
|
123 |
-
|
124 |
-
function getRandomVelocity() {
|
125 |
-
return new THREE.Vector3((Math.random() - 0.5) * 2, (Math.random() - 0.5) * 2, (Math.random() - 0.5) * 2).normalize();
|
126 |
-
}
|
127 |
-
|
128 |
-
function registerEvents() {
|
129 |
-
document.addEventListener('mousedown', onMouseDown);
|
130 |
-
document.addEventListener('keydown', onKeyDown);
|
131 |
-
document.addEventListener('keyup', onKeyUp);
|
132 |
-
document.addEventListener('mousemove', onMouseMove);
|
133 |
-
document.addEventListener('mouseleave', onMouseLeave);
|
134 |
-
window.addEventListener('resize', onWindowResize, false);
|
135 |
-
}
|
136 |
-
|
137 |
-
function fetchLetters() {
|
138 |
-
fetch('https://api11.salmonground-a8f39f59.centralus.azurecontainerapps.io/selftest', {
|
139 |
-
method: 'GET',
|
140 |
-
headers: {
|
141 |
-
'Accept': 'application/json'
|
142 |
-
}
|
143 |
-
})
|
144 |
-
.then(response => response.json())
|
145 |
-
.then(data => {
|
146 |
-
var queryResults = data.QueryResults;
|
147 |
-
queryResults = queryResults.substring(0, 10);
|
148 |
-
var fontLoader = new THREE.FontLoader();
|
149 |
-
fontLoader.load('https://threejs.org/examples/fonts/helvetiker_regular.typeface.json', function(font) {
|
150 |
-
for (var i = 0; i < queryResults.length; i++) {
|
151 |
-
var letter = queryResults[i].toLowerCase();
|
152 |
-
if (letter.match(/[a-z]/i)) {
|
153 |
-
var letterGeometry = new THREE.TextGeometry(letter, {
|
154 |
-
font: font,
|
155 |
-
size: 1,
|
156 |
-
height: 0.5,
|
157 |
-
curveSegments: 12,
|
158 |
-
bevelEnabled: false
|
159 |
-
});
|
160 |
-
var letterMaterial = new THREE.MeshLambertMaterial({ color: 0xffffff });
|
161 |
-
var letterMesh = createMesh(letterGeometry, letterMaterial);
|
162 |
-
balls.push(letterMesh);
|
163 |
-
}
|
164 |
-
}
|
165 |
-
});
|
166 |
-
});
|
167 |
-
}
|
168 |
-
|
169 |
-
function animate() {
|
170 |
-
// Rest of your animate function
|
171 |
-
}
|
172 |
-
|
173 |
-
function onMouseDown(event) {
|
174 |
-
// Your mouse down event
|
175 |
-
}
|
176 |
-
|
177 |
-
function onKeyDown(event) {
|
178 |
-
keys[event.keyCode] = true;
|
179 |
-
}
|
180 |
-
|
181 |
-
function onKeyUp(event) {
|
182 |
-
keys[event.keyCode] = false;
|
183 |
-
}
|
184 |
-
|
185 |
-
function onMouseMove(event) {
|
186 |
-
mouseX = event.clientX;
|
187 |
-
mouseY = event.clientY;
|
188 |
-
}
|
189 |
-
|
190 |
-
function onMouseLeave(event) {
|
191 |
-
mouseX = null;
|
192 |
-
mouseY = null;
|
193 |
-
}
|
194 |
-
|
195 |
-
function onWindowResize() {
|
196 |
-
camera.aspect = window.innerWidth / window.innerHeight;
|
197 |
-
camera.updateProjectionMatrix();
|
198 |
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
199 |
-
}
|
200 |
-
</script>
|
201 |
</body>
|
202 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
<head>
|
4 |
+
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
</head>
|
6 |
<body>
|
7 |
+
<a-scene background="color: #ECECEC">
|
8 |
+
<a-entity id="camera" position="0 1.6 3">
|
9 |
+
<a-camera></a-camera>
|
10 |
+
</a-entity>
|
11 |
+
|
12 |
+
<a-box id="paddle" position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" shadow></a-box>
|
13 |
+
<a-sphere id="ball" position="0 1.25 -5" radius="0.25" color="#EF2D5E" shadow></a-sphere>
|
14 |
+
|
15 |
+
<!-- Creating bricks -->
|
16 |
+
<a-box id="brick1" position="-1 0.5 -6" rotation="0 0 0" color="#7BC8A4" shadow></a-box>
|
17 |
+
<a-box id="brick2" position="0 0.5 -6" rotation="0 0 0" color="#7BC8A4" shadow></a-box>
|
18 |
+
<a-box id="brick3" position="1 0.5 -6" rotation="0 0 0" color="#7BC8A4" shadow></a-box>
|
19 |
+
</a-scene>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
</body>
|
21 |
</html>
|