Sunghokim commited on
Commit
9d0ee73
·
verified ·
1 Parent(s): e137815

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +277 -19
index.html CHANGED
@@ -1,19 +1,277 @@
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>Dodge Ball Game</title>
7
+ <style>
8
+ body {
9
+ margin: 0;
10
+ display: flex;
11
+ justify-content: center;
12
+ align-items: center;
13
+ min-height: 100vh;
14
+ background: #1a1a1a;
15
+ font-family: Arial, sans-serif;
16
+ }
17
+
18
+ #gameContainer {
19
+ position: relative;
20
+ width: 800px;
21
+ height: 600px;
22
+ background: #2a2a2a;
23
+ overflow: hidden;
24
+ border-radius: 10px;
25
+ box-shadow: 0 0 20px rgba(0,0,0,0.3);
26
+ }
27
+
28
+ #player {
29
+ position: absolute;
30
+ width: 30px;
31
+ height: 30px;
32
+ background: #5eff5e;
33
+ border-radius: 50%;
34
+ transition: transform 0.1s;
35
+ }
36
+
37
+ .ball {
38
+ position: absolute;
39
+ width: 20px;
40
+ height: 20px;
41
+ background: #ff5e5e;
42
+ border-radius: 50%;
43
+ }
44
+
45
+ #score {
46
+ position: absolute;
47
+ top: 20px;
48
+ right: 20px;
49
+ color: white;
50
+ font-size: 24px;
51
+ }
52
+
53
+ #startScreen {
54
+ position: absolute;
55
+ width: 100%;
56
+ height: 100%;
57
+ background: rgba(0,0,0,0.8);
58
+ display: flex;
59
+ flex-direction: column;
60
+ justify-content: center;
61
+ align-items: center;
62
+ color: white;
63
+ }
64
+
65
+ button {
66
+ padding: 15px 30px;
67
+ font-size: 20px;
68
+ background: #5eff5e;
69
+ border: none;
70
+ border-radius: 5px;
71
+ cursor: pointer;
72
+ margin-top: 20px;
73
+ }
74
+
75
+ button:hover {
76
+ background: #4acc4a;
77
+ }
78
+
79
+ .powerUp {
80
+ position: absolute;
81
+ width: 25px;
82
+ height: 25px;
83
+ background: #5e5eff;
84
+ border-radius: 50%;
85
+ animation: pulse 1s infinite;
86
+ }
87
+
88
+ @keyframes pulse {
89
+ 0% { transform: scale(1); }
90
+ 50% { transform: scale(1.2); }
91
+ 100% { transform: scale(1); }
92
+ }
93
+ </style>
94
+ </head>
95
+ <body>
96
+ <div id="gameContainer">
97
+ <div id="startScreen">
98
+ <h1>Dodge Ball</h1>
99
+ <button onclick="startGame()">Start Game</button>
100
+ </div>
101
+ <div id="player"></div>
102
+ <div id="score">Score: 0</div>
103
+ </div>
104
+
105
+ <script>
106
+ const gameContainer = document.getElementById('gameContainer');
107
+ const player = document.getElementById('player');
108
+ const scoreElement = document.getElementById('score');
109
+ const startScreen = document.getElementById('startScreen');
110
+
111
+ let score = 0;
112
+ let gameLoop;
113
+ let balls = [];
114
+ let powerUps = [];
115
+ let isGameRunning = false;
116
+ let playerSpeed = 5;
117
+ let keys = {};
118
+
119
+ player.style.left = '385px';
120
+ player.style.top = '285px';
121
+
122
+ function startGame() {
123
+ if (isGameRunning) return;
124
+
125
+ startScreen.style.display = 'none';
126
+ isGameRunning = true;
127
+ score = 0;
128
+ scoreElement.textContent = `Score: ${score}`;
129
+ balls = [];
130
+ powerUps = [];
131
+
132
+ gameLoop = setInterval(() => {
133
+ if (Math.random() < 0.03) createBall();
134
+ if (Math.random() < 0.01) createPowerUp();
135
+ updateGame();
136
+ }, 16);
137
+ }
138
+
139
+ function createBall() {
140
+ const ball = document.createElement('div');
141
+ ball.className = 'ball';
142
+ const side = Math.floor(Math.random() * 4);
143
+ let x, y, dx, dy;
144
+
145
+ switch(side) {
146
+ case 0: // top
147
+ x = Math.random() * 800;
148
+ y = -20;
149
+ dx = (Math.random() - 0.5) * 4;
150
+ dy = 2 + Math.random() * 2;
151
+ break;
152
+ case 1: // right
153
+ x = 820;
154
+ y = Math.random() * 600;
155
+ dx = -(2 + Math.random() * 2);
156
+ dy = (Math.random() - 0.5) * 4;
157
+ break;
158
+ case 2: // bottom
159
+ x = Math.random() * 800;
160
+ y = 620;
161
+ dx = (Math.random() - 0.5) * 4;
162
+ dy = -(2 + Math.random() * 2);
163
+ break;
164
+ case 3: // left
165
+ x = -20;
166
+ y = Math.random() * 600;
167
+ dx = 2 + Math.random() * 2;
168
+ dy = (Math.random() - 0.5) * 4;
169
+ break;
170
+ }
171
+
172
+ balls.push({ element: ball, x, y, dx, dy });
173
+ gameContainer.appendChild(ball);
174
+ }
175
+
176
+ function createPowerUp() {
177
+ const powerUp = document.createElement('div');
178
+ powerUp.className = 'powerUp';
179
+ const x = Math.random() * 750;
180
+ const y = Math.random() * 550;
181
+ powerUps.push({ element: powerUp, x, y });
182
+ powerUp.style.left = `${x}px`;
183
+ powerUp.style.top = `${y}px`;
184
+ gameContainer.appendChild(powerUp);
185
+ }
186
+
187
+ function updateGame() {
188
+ const playerRect = player.getBoundingClientRect();
189
+ const containerRect = gameContainer.getBoundingClientRect();
190
+
191
+ let playerX = parseInt(player.style.left);
192
+ let playerY = parseInt(player.style.top);
193
+
194
+ if (keys.ArrowLeft) playerX -= playerSpeed;
195
+ if (keys.ArrowRight) playerX += playerSpeed;
196
+ if (keys.ArrowUp) playerY -= playerSpeed;
197
+ if (keys.ArrowDown) playerY += playerSpeed;
198
+
199
+ playerX = Math.max(0, Math.min(770, playerX));
200
+ playerY = Math.max(0, Math.min(570, playerY));
201
+
202
+ player.style.left = `${playerX}px`;
203
+ player.style.top = `${playerY}px`;
204
+
205
+ // Update balls
206
+ for (let i = balls.length - 1; i >= 0; i--) {
207
+ const ball = balls[i];
208
+ ball.x += ball.dx;
209
+ ball.y += ball.dy;
210
+
211
+ if (ball.x < -50 || ball.x > 850 || ball.y < -50 || ball.y > 650) {
212
+ gameContainer.removeChild(ball.element);
213
+ balls.splice(i, 1);
214
+ continue;
215
+ }
216
+
217
+ ball.element.style.left = `${ball.x}px`;
218
+ ball.element.style.top = `${ball.y}px`;
219
+
220
+ const ballRect = ball.element.getBoundingClientRect();
221
+ if (checkCollision(playerRect, ballRect)) {
222
+ gameOver();
223
+ return;
224
+ }
225
+ }
226
+
227
+ // Check power-ups
228
+ for (let i = powerUps.length - 1; i >= 0; i--) {
229
+ const powerUp = powerUps[i];
230
+ const powerUpRect = powerUp.element.getBoundingClientRect();
231
+
232
+ if (checkCollision(playerRect, powerUpRect)) {
233
+ gameContainer.removeChild(powerUp.element);
234
+ powerUps.splice(i, 1);
235
+ score += 100;
236
+ scoreElement.textContent = `Score: ${score}`;
237
+ playerSpeed = 8;
238
+ setTimeout(() => playerSpeed = 5, 3000);
239
+ }
240
+ }
241
+
242
+ score++;
243
+ scoreElement.textContent = `Score: ${score}`;
244
+ }
245
+
246
+ function checkCollision(rect1, rect2) {
247
+ return !(rect1.right < rect2.left ||
248
+ rect1.left > rect2.right ||
249
+ rect1.bottom < rect2.top ||
250
+ rect1.top > rect2.bottom);
251
+ }
252
+
253
+ function gameOver() {
254
+ isGameRunning = false;
255
+ clearInterval(gameLoop);
256
+ startScreen.style.display = 'flex';
257
+ startScreen.querySelector('h1').textContent = `Game Over! Score: ${score}`;
258
+
259
+ balls.forEach(ball => gameContainer.removeChild(ball.element));
260
+ powerUps.forEach(powerUp => gameContainer.removeChild(powerUp.element));
261
+ balls = [];
262
+ powerUps = [];
263
+
264
+ player.style.left = '385px';
265
+ player.style.top = '285px';
266
+ }
267
+
268
+ document.addEventListener('keydown', (e) => {
269
+ keys[e.key] = true;
270
+ });
271
+
272
+ document.addEventListener('keyup', (e) => {
273
+ keys[e.key] = false;
274
+ });
275
+ </script>
276
+ </body>
277
+ </html>