gini1 commited on
Commit
6ff4d9b
โ€ข
1 Parent(s): 726fff4

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +22 -135
index.html CHANGED
@@ -1,162 +1,49 @@
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
- <title>Survival Game</title>
5
  <style>
6
  body { margin: 0; }
7
- canvas { display: block; }
8
- #gameInfo {
9
- position: absolute;
10
- top: 10px;
11
- left: 10px;
12
- background: rgba(0,0,0,0.7);
13
- color: white;
14
- padding: 10px;
15
- border-radius: 5px;
16
- z-index: 100;
17
- }
18
  </style>
19
  </head>
20
  <body>
21
- <div id="gameInfo">
22
- Click to start<br>
23
- WASD - Move<br>
24
- Mouse - Look Around
25
- </div>
26
-
27
  <script type="module">
28
- import * as THREE from 'https://unpkg.com/three@0.149.0/build/three.module.js';
29
- import { PointerLockControls } from 'https://unpkg.com/three@0.149.0/examples/jsm/controls/PointerLockControls.js';
30
-
31
- // ๋ฉ”์ธ ๋ณ€์ˆ˜
32
- let scene, camera, renderer, controls;
33
-
34
- // ์ดˆ๊ธฐํ™” ํ•จ์ˆ˜
35
- function init() {
36
- // Scene ์ƒ์„ฑ
37
- scene = new THREE.Scene();
38
- scene.background = new THREE.Color(0x87ceeb); // ํ•˜๋Š˜์ƒ‰ ๋ฐฐ๊ฒฝ
39
-
40
- // Camera ์„ค์ •
41
- camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
42
- camera.position.set(0, 5, 10);
43
-
44
- // Renderer ์„ค์ •
45
- renderer = new THREE.WebGLRenderer({ antialias: true });
46
- renderer.setSize(window.innerWidth, window.innerHeight);
47
- renderer.shadowMap.enabled = true;
48
- document.body.appendChild(renderer.domElement);
49
-
50
- // Controls ์„ค์ •
51
- controls = new PointerLockControls(camera, document.body);
52
-
53
- // ํด๋ฆญ ์ด๋ฒคํŠธ
54
- document.addEventListener('click', function() {
55
- controls.lock();
56
- });
57
-
58
- // ๊ธฐ๋ณธ ์ง€ํ˜• ์ƒ์„ฑ
59
- createGround();
60
-
61
- // ๊ธฐ๋ณธ ์กฐ๋ช… ์ถ”๊ฐ€
62
- addLights();
63
-
64
- // ํ…Œ์ŠคํŠธ์šฉ ๋ฐ•์Šค ์ถ”๊ฐ€
65
- addTestBox();
66
- }
67
-
68
- // ์ง€ํ˜• ์ƒ์„ฑ ํ•จ์ˆ˜
69
- function createGround() {
70
- const groundGeometry = new THREE.PlaneGeometry(100, 100);
71
- const groundMaterial = new THREE.MeshStandardMaterial({
72
- color: 0x3a8c3a,
73
- roughness: 0.8,
74
- metalness: 0.2
75
- });
76
- const ground = new THREE.Mesh(groundGeometry, groundMaterial);
77
- ground.rotation.x = -Math.PI / 2;
78
- ground.receiveShadow = true;
79
- scene.add(ground);
80
- }
81
-
82
- // ์กฐ๋ช… ์ถ”๊ฐ€ ํ•จ์ˆ˜
83
- function addLights() {
84
- // ์ฃผ๋ณ€๊ด‘
85
- const ambientLight = new THREE.AmbientLight(0xffffff, 0.6);
86
- scene.add(ambientLight);
87
-
88
- // ์ง์‚ฌ๊ด‘
89
- const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
90
- directionalLight.position.set(20, 30, 20);
91
- directionalLight.castShadow = true;
92
- scene.add(directionalLight);
93
- }
94
 
95
- // ํ…Œ์ŠคํŠธ์šฉ ๋ฐ•์Šค ์ถ”๊ฐ€
96
- function addTestBox() {
97
- const boxGeometry = new THREE.BoxGeometry(2, 2, 2);
98
- const boxMaterial = new THREE.MeshStandardMaterial({ color: 0xff0000 });
99
- const box = new THREE.Mesh(boxGeometry, boxMaterial);
100
- box.position.set(0, 1, -5);
101
- box.castShadow = true;
102
- box.receiveShadow = true;
103
- scene.add(box);
104
- }
105
-
106
- // ์›€์ง์ž„ ๊ด€๋ จ ๋ณ€์ˆ˜๋“ค
107
- const moveState = {
108
- forward: false,
109
- backward: false,
110
- left: false,
111
- right: false
112
- };
113
 
114
- // ํ‚ค๋ณด๋“œ ์ด๋ฒคํŠธ ์ฒ˜๋ฆฌ
115
- document.addEventListener('keydown', (event) => {
116
- switch (event.code) {
117
- case 'KeyW': moveState.forward = true; break;
118
- case 'KeyS': moveState.backward = true; break;
119
- case 'KeyA': moveState.left = true; break;
120
- case 'KeyD': moveState.right = true; break;
121
- }
122
- });
123
 
124
- document.addEventListener('keyup', (event) => {
125
- switch (event.code) {
126
- case 'KeyW': moveState.forward = false; break;
127
- case 'KeyS': moveState.backward = false; break;
128
- case 'KeyA': moveState.left = false; break;
129
- case 'KeyD': moveState.right = false; break;
130
- }
131
- });
132
 
133
- // ์• ๋‹ˆ๋ฉ”์ด์…˜ ํ•จ์ˆ˜
134
  function animate() {
135
  requestAnimationFrame(animate);
136
 
137
- if (controls.isLocked) {
138
- const speed = 0.2;
139
- if (moveState.forward) controls.moveForward(speed);
140
- if (moveState.backward) controls.moveForward(-speed);
141
- if (moveState.left) controls.moveRight(-speed);
142
- if (moveState.right) controls.moveRight(speed);
143
- }
144
 
145
  renderer.render(scene, camera);
146
  }
147
 
148
  // ํ™”๋ฉด ํฌ๊ธฐ ์กฐ์ • ์ฒ˜๋ฆฌ
149
- window.addEventListener('resize', onWindowResize, false);
150
-
151
- function onWindowResize() {
152
  camera.aspect = window.innerWidth / window.innerHeight;
153
  camera.updateProjectionMatrix();
154
- renderer.setSize(window.innerWidth, window.innerHeight);
155
- }
156
 
157
- // ์ดˆ๊ธฐํ™” ๋ฐ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์‹œ์ž‘
158
- init();
159
  animate();
160
  </script>
161
  </body>
162
- </html>
 
1
  <!DOCTYPE html>
2
  <html>
3
  <head>
4
+ <title>Basic Three.js Test</title>
5
  <style>
6
  body { margin: 0; }
 
 
 
 
 
 
 
 
 
 
 
7
  </style>
8
  </head>
9
  <body>
 
 
 
 
 
 
10
  <script type="module">
11
+ import * as THREE from 'https://unpkg.com/three@0.157.0/build/three.module.js';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
+ // ๊ธฐ๋ณธ ์„ค์ •
14
+ const scene = new THREE.Scene();
15
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
16
+ const renderer = new THREE.WebGLRenderer();
17
+
18
+ renderer.setSize(window.innerWidth, window.innerHeight);
19
+ document.body.appendChild(renderer.domElement);
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ // ํ…Œ์ŠคํŠธ์šฉ ํ๋ธŒ ์ƒ์„ฑ
22
+ const geometry = new THREE.BoxGeometry();
23
+ const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
24
+ const cube = new THREE.Mesh(geometry, material);
25
+ scene.add(cube);
 
 
 
 
26
 
27
+ camera.position.z = 5;
 
 
 
 
 
 
 
28
 
29
+ // ์• ๋‹ˆ๋ฉ”์ด์…˜
30
  function animate() {
31
  requestAnimationFrame(animate);
32
 
33
+ cube.rotation.x += 0.01;
34
+ cube.rotation.y += 0.01;
 
 
 
 
 
35
 
36
  renderer.render(scene, camera);
37
  }
38
 
39
  // ํ™”๋ฉด ํฌ๊ธฐ ์กฐ์ • ์ฒ˜๋ฆฌ
40
+ window.addEventListener('resize', () => {
41
+ renderer.setSize(window.innerWidth, window.innerHeight);
 
42
  camera.aspect = window.innerWidth / window.innerHeight;
43
  camera.updateProjectionMatrix();
44
+ });
 
45
 
 
 
46
  animate();
47
  </script>
48
  </body>
49
+ </html>