Spaces:
Running
Running
Update index.html
Browse files- index.html +83 -71
index.html
CHANGED
@@ -1,92 +1,104 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html
|
3 |
<head>
|
4 |
-
<meta charset="
|
5 |
-
<title>
|
6 |
<style>
|
7 |
body {
|
8 |
margin: 0;
|
9 |
overflow: hidden;
|
10 |
}
|
|
|
|
|
|
|
|
|
11 |
</style>
|
12 |
</head>
|
13 |
<body>
|
14 |
-
<script src="https://
|
15 |
-
<script src="https://threejs.org/examples/js/controls/OrbitControls.js"></script>
|
16 |
-
<script src="https://threejs.org/examples/js/libs/dat.gui.min.js"></script>
|
17 |
-
<script src="https://threejs.org/examples/js/curves/NURBSCurve.js"></script>
|
18 |
<script>
|
19 |
-
|
20 |
-
|
21 |
-
const scene = new THREE.Scene();
|
22 |
-
|
23 |
-
// Set up the camera
|
24 |
-
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
25 |
-
camera.position.z = 5;
|
26 |
-
|
27 |
-
// Set up the renderer
|
28 |
-
const renderer = new THREE.WebGLRenderer();
|
29 |
-
renderer.setSize(window.innerWidth, window.innerHeight);
|
30 |
-
document.body.appendChild(renderer.domElement);
|
31 |
-
|
32 |
-
// Set up the skybox
|
33 |
-
const loader = new THREE.CubeTextureLoader();
|
34 |
-
const texture = loader.load([
|
35 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/pz.jpg',
|
36 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nz.jpg',
|
37 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/py.jpg',
|
38 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/ny.jpg',
|
39 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/px.jpg',
|
40 |
-
'https://threejs.org/examples/textures/cube/SwedishRoyalCastle/nx.jpg'
|
41 |
-
]);
|
42 |
-
scene.background = texture;
|
43 |
-
|
44 |
-
// Set up the lighting
|
45 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5);
|
46 |
-
scene.add(ambientLight);
|
47 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
48 |
-
directionalLight.position.set(0, 1, 0);
|
49 |
-
scene.add(directionalLight);
|
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 |
-
window.onload = init;
|
90 |
</script>
|
91 |
</body>
|
92 |
-
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>Tilemap Example</title>
|
6 |
<style>
|
7 |
body {
|
8 |
margin: 0;
|
9 |
overflow: hidden;
|
10 |
}
|
11 |
+
canvas {
|
12 |
+
width: 100%;
|
13 |
+
height: 100%;
|
14 |
+
}
|
15 |
</style>
|
16 |
</head>
|
17 |
<body>
|
18 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
|
|
|
|
|
|
19 |
<script>
|
20 |
+
// create the scene
|
21 |
+
var scene = new THREE.Scene();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
// create the camera
|
24 |
+
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
25 |
+
camera.position.z = 5;
|
26 |
|
27 |
+
// create the renderer
|
28 |
+
var renderer = new THREE.WebGLRenderer();
|
29 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
30 |
+
document.body.appendChild(renderer.domElement);
|
31 |
|
32 |
+
// create the tilemap
|
33 |
+
var tilemap = [
|
34 |
+
[0, 0, 0, 0, 0],
|
35 |
+
[0, 1, 1, 1, 0],
|
36 |
+
[0, 1, 1, 1, 0],
|
37 |
+
[0, 1, 1, 1, 0],
|
38 |
+
[0, 0, 0, 0, 0],
|
39 |
+
];
|
40 |
+
var tileSize = 1;
|
41 |
+
var tileGeometry = new THREE.PlaneGeometry(tileSize, tileSize);
|
42 |
+
var tileMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
|
43 |
+
var tiles = [];
|
44 |
+
for (var i = 0; i < tilemap.length; i++) {
|
45 |
+
for (var j = 0; j < tilemap[i].length; j++) {
|
46 |
+
if (tilemap[i][j] === 1) {
|
47 |
+
var tile = new THREE.Mesh(tileGeometry, tileMaterial);
|
48 |
+
tile.position.x = (j - tilemap[i].length / 2) * tileSize;
|
49 |
+
tile.position.y = (-i + tilemap.length / 2) * tileSize;
|
50 |
+
scene.add(tile);
|
51 |
+
tiles.push(tile);
|
52 |
+
}
|
53 |
+
}
|
54 |
+
}
|
55 |
|
56 |
+
// create the arrow buttons
|
57 |
+
var arrowUp = document.createElement('button');
|
58 |
+
arrowUp.innerText = '↑';
|
59 |
+
arrowUp.style.position = 'absolute';
|
60 |
+
arrowUp.style.left = '50%';
|
61 |
+
arrowUp.style.top = '10px';
|
62 |
+
arrowUp.addEventListener('click', function() {
|
63 |
+
camera.position.y += 1;
|
64 |
+
});
|
65 |
+
document.body.appendChild(arrowUp);
|
66 |
|
67 |
+
var arrowDown = document.createElement('button');
|
68 |
+
arrowDown.innerText = '↓';
|
69 |
+
arrowDown.style.position = 'absolute';
|
70 |
+
arrowDown.style.left = '50%';
|
71 |
+
arrowDown.style.bottom = '10px';
|
72 |
+
arrowDown.addEventListener('click', function() {
|
73 |
+
camera.position.y -= 1;
|
74 |
+
});
|
75 |
+
document.body.appendChild(arrowDown);
|
76 |
|
77 |
+
var arrowLeft = document.createElement('button');
|
78 |
+
arrowLeft.innerText = '←';
|
79 |
+
arrowLeft.style.position = 'absolute';
|
80 |
+
arrowLeft.style.left = '10px';
|
81 |
+
arrowLeft.style.top = '50%';
|
82 |
+
arrowLeft.addEventListener('click', function() {
|
83 |
+
camera.position.x -= 1;
|
84 |
+
});
|
85 |
+
document.body.appendChild(arrowLeft);
|
86 |
|
87 |
+
var arrowRight = document.createElement('button');
|
88 |
+
arrowRight.innerText = '→';
|
89 |
+
arrowRight.style.position = 'absolute';
|
90 |
+
arrowRight.style.right = '10px';
|
91 |
+
arrowRight.style.top = '50%';
|
92 |
+
arrowRight.addEventListener('click(function() {
|
93 |
+
camera.position.x += 1;
|
94 |
+
});
|
95 |
+
document.body.appendChild(arrowRight);
|
96 |
+
// animate the scene
|
97 |
+
function animate() {
|
98 |
+
requestAnimationFrame(animate);
|
99 |
+
renderer.render(scene, camera);
|
100 |
}
|
101 |
+
animate();
|
|
|
102 |
</script>
|
103 |
</body>
|
104 |
+
</html>
|