yoon2566 commited on
Commit
c3b1015
Β·
verified Β·
1 Parent(s): 798841e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +289 -19
index.html CHANGED
@@ -1,19 +1,289 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Zombie Survival</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ overflow: hidden;
11
+ background: #333;
12
+ font-family: Arial, sans-serif;
13
+ cursor: crosshair;
14
+ }
15
+
16
+ #score, #health, #timer {
17
+ position: fixed;
18
+ color: white;
19
+ font-size: 20px;
20
+ z-index: 100;
21
+ }
22
+ #score {
23
+ top: 10px;
24
+ left: 10px;
25
+ }
26
+ #health {
27
+ top: 10px;
28
+ right: 10px;
29
+ }
30
+ #timer {
31
+ top: 10px;
32
+ left: 50%;
33
+ transform: translateX(-50%);
34
+ }
35
+
36
+ #startScreen {
37
+ position: fixed;
38
+ top: 0;
39
+ left: 0;
40
+ width: 100%;
41
+ height: 100%;
42
+ background: rgba(0, 0, 0, 0.8);
43
+ color: white;
44
+ display: flex;
45
+ justify-content: center;
46
+ align-items: center;
47
+ flex-direction: column;
48
+ z-index: 1000;
49
+ }
50
+
51
+ #startButton {
52
+ padding: 10px 20px;
53
+ font-size: 18px;
54
+ background: green;
55
+ color: white;
56
+ border: none;
57
+ cursor: pointer;
58
+ border-radius: 5px;
59
+ margin-top: 20px;
60
+ }
61
+
62
+ #player {
63
+ position: absolute;
64
+ width: 40px;
65
+ height: 40px;
66
+ background: lime;
67
+ border-radius: 50%;
68
+ transform-origin: center;
69
+ }
70
+
71
+ .zombie {
72
+ position: absolute;
73
+ width: 40px;
74
+ height: 40px;
75
+ background: crimson;
76
+ border-radius: 50%;
77
+ }
78
+
79
+ .bullet {
80
+ position: absolute;
81
+ width: 8px;
82
+ height: 8px;
83
+ background: yellow;
84
+ border-radius: 50%;
85
+ }
86
+ </style>
87
+ </head>
88
+ <body>
89
+ <div id="startScreen">
90
+ <h1>Zombie Survival</h1>
91
+ <button id="startButton">Start Game</button>
92
+ </div>
93
+ <div id="score">Score: 0</div>
94
+ <div id="health">Health: 100</div>
95
+ <div id="timer">Time: 0</div>
96
+ <div id="player"></div>
97
+
98
+ <script>
99
+ const startScreen = document.getElementById('startScreen');
100
+ const startButton = document.getElementById('startButton');
101
+ const player = document.getElementById('player');
102
+ const scoreDisplay = document.getElementById('score');
103
+ const healthDisplay = document.getElementById('health');
104
+ const timerDisplay = document.getElementById('timer');
105
+
106
+ let score = 0;
107
+ let health = 100;
108
+ let gameRunning = false;
109
+ let bullets = [];
110
+ let zombies = [];
111
+ let mouseX = 0, mouseY = 0;
112
+ let playerX = window.innerWidth / 2;
113
+ let playerY = window.innerHeight / 2;
114
+ let gameTime = 0;
115
+ let zombieSpeedMultiplier = 1;
116
+ let timeInterval;
117
+
118
+ // ν”Œλ ˆμ΄μ–΄ 이동 μ—…λ°μ΄νŠΈ
119
+ function updatePlayer() {
120
+ player.style.left = `${playerX - 20}px`;
121
+ player.style.top = `${playerY - 20}px`;
122
+ }
123
+
124
+ // μ’€λΉ„ 생성
125
+ function spawnZombie() {
126
+ if (!gameRunning) return;
127
+
128
+ const zombie = document.createElement('div');
129
+ zombie.className = 'zombie';
130
+ const size = 40;
131
+
132
+ const side = Math.floor(Math.random() * 4); // 0: μœ„, 1: 였λ₯Έμͺ½, 2: μ•„λž˜, 3: μ™Όμͺ½
133
+ let x, y;
134
+
135
+ if (side === 0) { // μœ„μͺ½μ—μ„œ 생성
136
+ x = Math.random() * window.innerWidth;
137
+ y = -size;
138
+ } else if (side === 1) { // 였λ₯Έμͺ½μ—μ„œ 생성
139
+ x = window.innerWidth + size;
140
+ y = Math.random() * window.innerHeight;
141
+ } else if (side === 2) { // μ•„λž˜μͺ½μ—μ„œ 생성
142
+ x = Math.random() * window.innerWidth;
143
+ y = window.innerHeight + size;
144
+ } else { // μ™Όμͺ½μ—μ„œ 생성
145
+ x = -size;
146
+ y = Math.random() * window.innerHeight;
147
+ }
148
+
149
+ document.body.appendChild(zombie);
150
+ zombies.push({ element: zombie, x, y, speed: (1.5 + Math.random() * 2) * zombieSpeedMultiplier });
151
+
152
+ updateZombies();
153
+ }
154
+
155
+ // μ’€λΉ„ 이동 및 좩돌 처리
156
+ function updateZombies() {
157
+ zombies.forEach((zombie, index) => {
158
+ const angle = Math.atan2(playerY - zombie.y, playerX - zombie.x);
159
+ zombie.x += Math.cos(angle) * zombie.speed;
160
+ zombie.y += Math.sin(angle) * zombie.speed;
161
+ zombie.element.style.left = `${zombie.x - 20}px`;
162
+ zombie.element.style.top = `${zombie.y - 20}px`;
163
+
164
+ const distanceToPlayer = Math.hypot(zombie.x - playerX, zombie.y - playerY);
165
+ if (distanceToPlayer < 40) {
166
+ health -= 10;
167
+ healthDisplay.textContent = `Health: ${health}`;
168
+ zombie.element.remove();
169
+ zombies.splice(index, 1);
170
+
171
+ if (health <= 0) {
172
+ endGame();
173
+ }
174
+ }
175
+ });
176
+ }
177
+
178
+ // μ΄μ•Œ 생성
179
+ function shootBullet() {
180
+ if (!gameRunning) return;
181
+
182
+ const bullet = document.createElement('div');
183
+ bullet.className = 'bullet';
184
+ const angle = Math.atan2(mouseY - playerY, mouseX - playerX);
185
+ const speed = 10;
186
+
187
+ bullets.push({
188
+ element: bullet,
189
+ x: playerX,
190
+ y: playerY,
191
+ vx: Math.cos(angle) * speed,
192
+ vy: Math.sin(angle) * speed
193
+ });
194
+
195
+ document.body.appendChild(bullet);
196
+ }
197
+
198
+ // μ΄μ•Œ μ—…λ°μ΄νŠΈ
199
+ function updateBullets() {
200
+ bullets.forEach((bullet, index) => {
201
+ bullet.x += bullet.vx;
202
+ bullet.y += bullet.vy;
203
+
204
+ bullet.element.style.left = `${bullet.x - 4}px`;
205
+ bullet.element.style.top = `${bullet.y - 4}px`;
206
+
207
+ // ν™”λ©΄ λ°–μœΌλ‘œ λ‚˜κ°„ μ΄μ•Œ 제거
208
+ if (bullet.x < 0 || bullet.x > window.innerWidth || bullet.y < 0 || bullet.y > window.innerHeight) {
209
+ bullet.element.remove();
210
+ bullets.splice(index, 1);
211
+ }
212
+
213
+ // 쒀비와 좩돌 체크
214
+ zombies.forEach((zombie, zombieIndex) => {
215
+ const distance = Math.hypot(bullet.x - zombie.x, bullet.y - zombie.y);
216
+ if (distance < 20) {
217
+ bullet.element.remove();
218
+ zombie.element.remove();
219
+ bullets.splice(index, 1);
220
+ zombies.splice(zombieIndex, 1);
221
+ score += 10;
222
+ scoreDisplay.textContent = `Score: ${score}`;
223
+ }
224
+ });
225
+ });
226
+ }
227
+
228
+ // κ²Œμž„ 루프
229
+ function gameLoop() {
230
+ if (!gameRunning) return;
231
+
232
+ updateBullets();
233
+ updateZombies();
234
+ requestAnimationFrame(gameLoop);
235
+ }
236
+
237
+ // κ²Œμž„ μ‹œκ°„ μ—…λ°μ΄νŠΈ
238
+ function updateTimer() {
239
+ if (!gameRunning) return;
240
+ gameTime++;
241
+ timerDisplay.textContent = `Time: ${gameTime}`;
242
+ if (gameTime % 10 === 0) {
243
+ zombieSpeedMultiplier *= 2;
244
+ zombies.forEach(zombie => {
245
+ zombie.speed = (1.5 + Math.random() * 2) * zombieSpeedMultiplier;
246
+ });
247
+ }
248
+ }
249
+
250
+
251
+ // κ²Œμž„ μ‹œμž‘
252
+ startButton.addEventListener('click', () => {
253
+ startScreen.style.display = 'none';
254
+ gameRunning = true;
255
+ health = 100;
256
+ score = 0;
257
+ gameTime = 0;
258
+ zombieSpeedMultiplier = 1;
259
+ healthDisplay.textContent = `Health: ${health}`;
260
+ scoreDisplay.textContent = `Score: ${score}`;
261
+ timerDisplay.textContent = `Time: ${gameTime}`;
262
+ spawnZombie();
263
+ setInterval(spawnZombie, 1000);
264
+ gameLoop();
265
+ timeInterval = setInterval(updateTimer, 1000);
266
+ });
267
+
268
+ // κ²Œμž„ μ’…λ£Œ
269
+ function endGame() {
270
+ gameRunning = false;
271
+ clearInterval(timeInterval);
272
+ alert(`Game Over! Final Score: ${score}, Time: ${gameTime}`);
273
+ location.reload();
274
+ }
275
+
276
+ // 마우슀 이동
277
+ document.addEventListener('mousemove', (e) => {
278
+ mouseX = e.clientX;
279
+ mouseY = e.clientY;
280
+ });
281
+
282
+ // μ΄μ•Œ λ°œμ‚¬
283
+ document.addEventListener('click', shootBullet);
284
+
285
+ // 초기 ν”Œλ ˆμ΄μ–΄ μœ„μΉ˜
286
+ updatePlayer();
287
+ </script>
288
+ </body>
289
+ </html>