Tingchenliang commited on
Commit
5008555
·
verified ·
1 Parent(s): 8f9b7d5

Add 2 files

Browse files
Files changed (2) hide show
  1. README.md +7 -5
  2. index.html +727 -19
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Tempo Game
3
- emoji: 📚
4
- colorFrom: indigo
5
- colorTo: purple
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: tempo-game
3
+ emoji: 🐳
4
+ colorFrom: purple
5
+ colorTo: red
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,727 @@
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>桜のリズム - Sakura Rhythm</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
9
+ <style>
10
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700&display=swap');
11
+
12
+ body {
13
+ font-family: 'Noto Sans JP', sans-serif;
14
+ background-color: #0f0f1a;
15
+ color: #f8f8f8;
16
+ overflow: hidden;
17
+ }
18
+
19
+ .sakura {
20
+ position: absolute;
21
+ background-color: #ffb7c5;
22
+ width: 6px;
23
+ height: 6px;
24
+ border-radius: 50% 0 50% 50%;
25
+ transform: rotate(-45deg);
26
+ opacity: 0;
27
+ animation: fall linear infinite;
28
+ }
29
+
30
+ @keyframes fall {
31
+ 0% {
32
+ transform: translateY(-10vh) rotate(-45deg);
33
+ opacity: 0;
34
+ }
35
+ 10% {
36
+ opacity: 1;
37
+ }
38
+ 90% {
39
+ opacity: 1;
40
+ }
41
+ 100% {
42
+ transform: translateY(110vh) rotate(-45deg);
43
+ opacity: 0;
44
+ }
45
+ }
46
+
47
+ .hit-circle {
48
+ position: absolute;
49
+ width: 80px;
50
+ height: 80px;
51
+ border-radius: 50%;
52
+ background: radial-gradient(circle, #ff3366 0%, #990033 100%);
53
+ box-shadow: 0 0 20px #ff3366;
54
+ display: flex;
55
+ justify-content: center;
56
+ align-items: center;
57
+ color: white;
58
+ font-weight: bold;
59
+ font-size: 24px;
60
+ transform: scale(0);
61
+ opacity: 0;
62
+ transition: transform 0.2s, opacity 0.2s;
63
+ z-index: 10;
64
+ }
65
+
66
+ .hit-circle.active {
67
+ transform: scale(1);
68
+ opacity: 1;
69
+ }
70
+
71
+ .hit-circle.perfect {
72
+ background: radial-gradient(circle, #66ff33 0%, #339900 100%);
73
+ box-shadow: 0 0 20px #66ff33;
74
+ }
75
+
76
+ .hit-circle.good {
77
+ background: radial-gradient(circle, #3366ff 0%, #003399 100%);
78
+ box-shadow: 0 0 20px #3366ff;
79
+ }
80
+
81
+ .hit-circle.miss {
82
+ background: radial-gradient(circle, #888888 0%, #333333 100%);
83
+ box-shadow: 0 0 20px #888888;
84
+ }
85
+
86
+ .combo-display {
87
+ position: absolute;
88
+ font-size: 48px;
89
+ font-weight: bold;
90
+ color: #ffcc00;
91
+ text-shadow: 0 0 10px #ff9900;
92
+ opacity: 0;
93
+ transform: scale(0.5);
94
+ transition: all 0.3s;
95
+ z-index: 20;
96
+ }
97
+
98
+ .combo-display.show {
99
+ opacity: 1;
100
+ transform: scale(1);
101
+ }
102
+
103
+ .judgement {
104
+ position: absolute;
105
+ font-size: 36px;
106
+ font-weight: bold;
107
+ opacity: 0;
108
+ transform: translateY(20px);
109
+ transition: all 0.3s;
110
+ z-index: 20;
111
+ }
112
+
113
+ .judgement.show {
114
+ opacity: 1;
115
+ transform: translateY(0);
116
+ }
117
+
118
+ .judgement.perfect {
119
+ color: #66ff33;
120
+ text-shadow: 0 0 10px #339900;
121
+ }
122
+
123
+ .judgement.good {
124
+ color: #3366ff;
125
+ text-shadow: 0 0 10px #003399;
126
+ }
127
+
128
+ .judgement.miss {
129
+ color: #888888;
130
+ text-shadow: 0 0 10px #333333;
131
+ }
132
+
133
+ .progress-bar {
134
+ height: 4px;
135
+ background: linear-gradient(90deg, #ff3366, #990033);
136
+ transition: width 0.1s;
137
+ }
138
+
139
+ .torii-gate {
140
+ position: absolute;
141
+ bottom: 0;
142
+ left: 50%;
143
+ transform: translateX(-50%);
144
+ width: 200px;
145
+ height: 150px;
146
+ background-color: #cc0033;
147
+ clip-path: polygon(0 0, 100% 0, 90% 100%, 10% 100%);
148
+ z-index: 5;
149
+ }
150
+
151
+ .torii-gate:before {
152
+ content: '';
153
+ position: absolute;
154
+ top: 30px;
155
+ left: 20px;
156
+ right: 20px;
157
+ height: 20px;
158
+ background-color: #fff;
159
+ clip-path: polygon(0 0, 100% 0, 95% 100%, 5% 100%);
160
+ }
161
+
162
+ .torii-gate:after {
163
+ content: '鳥居';
164
+ position: absolute;
165
+ bottom: 10px;
166
+ left: 0;
167
+ right: 0;
168
+ text-align: center;
169
+ color: white;
170
+ font-weight: bold;
171
+ }
172
+ </style>
173
+ </head>
174
+ <body class="relative h-screen w-screen">
175
+ <!-- Sakura blossoms -->
176
+ <div id="sakura-container"></div>
177
+
178
+ <!-- Game elements -->
179
+ <div id="game-container" class="absolute inset-0 flex flex-col">
180
+ <!-- Header -->
181
+ <div class="flex justify-between items-center p-4">
182
+ <div class="text-2xl font-bold text-pink-500">桜のリズム</div>
183
+ <div class="flex space-x-4">
184
+ <div class="bg-gray-800 bg-opacity-50 rounded-full px-4 py-1">
185
+ <span class="text-yellow-300">スコア: </span>
186
+ <span id="score" class="font-bold">0</span>
187
+ </div>
188
+ <div class="bg-gray-800 bg-opacity-50 rounded-full px-4 py-1">
189
+ <span class="text-blue-300">コンボ: </span>
190
+ <span id="combo" class="font-bold">0</span>
191
+ </div>
192
+ <div class="bg-gray-800 bg-opacity-50 rounded-full px-4 py-1">
193
+ <span class="text-green-300">精度: </span>
194
+ <span id="accuracy" class="font-bold">100%</span>
195
+ </div>
196
+ </div>
197
+ </div>
198
+
199
+ <!-- Progress bar -->
200
+ <div class="w-full bg-gray-800 bg-opacity-50">
201
+ <div id="progress-bar" class="progress-bar" style="width: 0%"></div>
202
+ </div>
203
+
204
+ <!-- Main game area -->
205
+ <div class="flex-1 relative overflow-hidden">
206
+ <!-- Torii gate at bottom -->
207
+ <div class="torii-gate"></div>
208
+
209
+ <!-- Hit circles will be dynamically added here -->
210
+ </div>
211
+
212
+ <!-- Controls -->
213
+ <div class="flex justify-center p-4 space-x-8">
214
+ <button id="start-btn" class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-6 rounded-full transition-all transform hover:scale-105">
215
+ <i class="fas fa-play mr-2"></i>スタート
216
+ </button>
217
+ <button id="pause-btn" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-6 rounded-full transition-all transform hover:scale-105" disabled>
218
+ <i class="fas fa-pause mr-2"></i>一時停止
219
+ </button>
220
+ <div class="flex items-center space-x-2">
221
+ <span class="text-gray-400">難易度:</span>
222
+ <select id="difficulty" class="bg-gray-800 text-white rounded px-3 py-1">
223
+ <option value="easy">簡単</option>
224
+ <option value="medium" selected>普通</option>
225
+ <option value="hard">難しい</option>
226
+ <option value="expert">達人</option>
227
+ </select>
228
+ </div>
229
+ </div>
230
+ </div>
231
+
232
+ <!-- Song selection modal -->
233
+ <div id="song-modal" class="fixed inset-0 bg-black bg-opacity-80 flex items-center justify-center z-50">
234
+ <div class="bg-gray-900 rounded-lg p-6 w-full max-w-2xl">
235
+ <h2 class="text-2xl font-bold text-pink-500 mb-6 text-center">曲を選んでください</h2>
236
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
237
+ <div class="song-card bg-gray-800 rounded-lg p-4 hover:bg-gray-700 transition cursor-pointer" data-song="1">
238
+ <div class="text-xl font-bold text-white">桜の詩</div>
239
+ <div class="text-gray-400">BPM: 120</div>
240
+ </div>
241
+ <div class="song-card bg-gray-800 rounded-lg p-4 hover:bg-gray-700 transition cursor-pointer" data-song="2">
242
+ <div class="text-xl font-bold text-white">月のワルツ</div>
243
+ <div class="text-gray-400">BPM: 140</div>
244
+ </div>
245
+ <div class="song-card bg-gray-800 rounded-lg p-4 hover:bg-gray-700 transition cursor-pointer" data-song="3">
246
+ <div class="text-xl font-bold text-white">風の唄</div>
247
+ <div class="text-gray-400">BPM: 160</div>
248
+ </div>
249
+ <div class="song-card bg-gray-800 rounded-lg p-4 hover:bg-gray-700 transition cursor-pointer" data-song="4">
250
+ <div class="text-xl font-bold text-white">雷鳴</div>
251
+ <div class="text-gray-400">BPM: 180</div>
252
+ </div>
253
+ </div>
254
+ </div>
255
+ </div>
256
+
257
+ <script>
258
+ // Game state
259
+ const state = {
260
+ score: 0,
261
+ combo: 0,
262
+ hits: 0,
263
+ totalHits: 0,
264
+ gameActive: false,
265
+ currentSong: null,
266
+ difficulty: 'medium',
267
+ hitObjects: [],
268
+ nextHitTime: 0,
269
+ startTime: 0,
270
+ currentTime: 0,
271
+ audioContext: null,
272
+ audioBuffer: null,
273
+ audioSource: null,
274
+ analyser: null,
275
+ animationFrame: null
276
+ };
277
+
278
+ // Difficulty settings
279
+ const difficulties = {
280
+ easy: { speed: 1.0, spawnRate: 1500, accuracyWindow: 300 },
281
+ medium: { speed: 1.2, spawnRate: 1200, accuracyWindow: 250 },
282
+ hard: { speed: 1.5, spawnRate: 900, accuracyWindow: 200 },
283
+ expert: { speed: 2.0, spawnRate: 600, accuracyWindow: 150 }
284
+ };
285
+
286
+ // Songs data
287
+ const songs = {
288
+ 1: { name: '桜の詩', bpm: 120, pattern: [1, 2, 3, 4] },
289
+ 2: { name: '月のワルツ', bpm: 140, pattern: [1, 3, 2, 4] },
290
+ 3: { name: '風の唄', bpm: 160, pattern: [1, 4, 2, 3] },
291
+ 4: { name: '雷鳴', bpm: 180, pattern: [1, 2, 1, 3, 4] }
292
+ };
293
+
294
+ // DOM elements
295
+ const elements = {
296
+ gameContainer: document.getElementById('game-container'),
297
+ sakuraContainer: document.getElementById('sakura-container'),
298
+ score: document.getElementById('score'),
299
+ combo: document.getElementById('combo'),
300
+ accuracy: document.getElementById('accuracy'),
301
+ progressBar: document.getElementById('progress-bar'),
302
+ startBtn: document.getElementById('start-btn'),
303
+ pauseBtn: document.getElementById('pause-btn'),
304
+ difficulty: document.getElementById('difficulty'),
305
+ songModal: document.getElementById('song-modal'),
306
+ songCards: document.querySelectorAll('.song-card')
307
+ };
308
+
309
+ // Initialize game
310
+ function init() {
311
+ // Create sakura blossoms
312
+ createSakura();
313
+
314
+ // Event listeners
315
+ elements.startBtn.addEventListener('click', startGame);
316
+ elements.pauseBtn.addEventListener('click', pauseGame);
317
+ elements.difficulty.addEventListener('change', updateDifficulty);
318
+
319
+ elements.songCards.forEach(card => {
320
+ card.addEventListener('click', () => selectSong(card.dataset.song));
321
+ });
322
+
323
+ // Show song selection modal
324
+ elements.songModal.classList.remove('hidden');
325
+
326
+ // Set up keyboard controls
327
+ document.addEventListener('keydown', handleKeyPress);
328
+
329
+ // Set up click/tap controls
330
+ elements.gameContainer.addEventListener('click', handleTap);
331
+ }
332
+
333
+ // Create sakura blossoms
334
+ function createSakura() {
335
+ for (let i = 0; i < 30; i++) {
336
+ const sakura = document.createElement('div');
337
+ sakura.className = 'sakura';
338
+
339
+ // Random position and size
340
+ const size = Math.random() * 6 + 4;
341
+ sakura.style.width = `${size}px`;
342
+ sakura.style.height = `${size}px`;
343
+ sakura.style.left = `${Math.random() * 100}%`;
344
+
345
+ // Random animation duration and delay
346
+ const duration = Math.random() * 10 + 5;
347
+ const delay = Math.random() * 10;
348
+ sakura.style.animationDuration = `${duration}s`;
349
+ sakura.style.animationDelay = `${delay}s`;
350
+
351
+ elements.sakuraContainer.appendChild(sakura);
352
+ }
353
+ }
354
+
355
+ // Select song
356
+ function selectSong(songId) {
357
+ state.currentSong = songs[songId];
358
+ elements.songModal.classList.add('hidden');
359
+
360
+ // Update UI with song info
361
+ document.querySelector('.text-pink-500').textContent = `桜のリズム - ${state.currentSong.name}`;
362
+
363
+ // Initialize audio context
364
+ state.audioContext = new (window.AudioContext || window.webkitAudioContext)();
365
+ state.analyser = state.audioContext.createAnalyser();
366
+
367
+ // For demo purposes, we'll simulate audio with a timer
368
+ // In a real game, you would load actual audio files here
369
+ }
370
+
371
+ // Update difficulty
372
+ function updateDifficulty() {
373
+ state.difficulty = elements.difficulty.value;
374
+ }
375
+
376
+ // Start game
377
+ function startGame() {
378
+ if (!state.currentSong) {
379
+ elements.songModal.classList.remove('hidden');
380
+ return;
381
+ }
382
+
383
+ if (state.gameActive) return;
384
+
385
+ // Reset game state
386
+ state.score = 0;
387
+ state.combo = 0;
388
+ state.hits = 0;
389
+ state.totalHits = 0;
390
+ state.hitObjects = [];
391
+ state.nextHitTime = 0;
392
+ state.gameActive = true;
393
+
394
+ // Update UI
395
+ elements.score.textContent = '0';
396
+ elements.combo.textContent = '0';
397
+ elements.accuracy.textContent = '100%';
398
+ elements.progressBar.style.width = '0%';
399
+
400
+ // Clear existing hit objects
401
+ document.querySelectorAll('.hit-circle').forEach(el => el.remove());
402
+ document.querySelectorAll('.combo-display').forEach(el => el.remove());
403
+ document.querySelectorAll('.judgement').forEach(el => el.remove());
404
+
405
+ // Enable/disable buttons
406
+ elements.startBtn.disabled = true;
407
+ elements.pauseBtn.disabled = false;
408
+
409
+ // Start music (simulated)
410
+ state.startTime = Date.now();
411
+ state.currentTime = 0;
412
+
413
+ // Start game loop
414
+ gameLoop();
415
+ }
416
+
417
+ // Pause game
418
+ function pauseGame() {
419
+ if (!state.gameActive) return;
420
+
421
+ state.gameActive = false;
422
+
423
+ // Pause audio
424
+ if (state.audioSource) {
425
+ state.audioSource.stop();
426
+ state.audioSource = null;
427
+ }
428
+
429
+ // Cancel animation frame
430
+ if (state.animationFrame) {
431
+ cancelAnimationFrame(state.animationFrame);
432
+ state.animationFrame = null;
433
+ }
434
+
435
+ // Update buttons
436
+ elements.startBtn.disabled = false;
437
+ elements.pauseBtn.disabled = true;
438
+ }
439
+
440
+ // Game loop
441
+ function gameLoop() {
442
+ if (!state.gameActive) return;
443
+
444
+ state.currentTime = Date.now() - state.startTime;
445
+
446
+ // Update progress bar
447
+ const progress = (state.currentTime / 60000) * 100; // Demo: 1 minute song
448
+ elements.progressBar.style.width = `${Math.min(progress, 100)}%`;
449
+
450
+ // Spawn hit objects
451
+ const difficultySettings = difficulties[state.difficulty];
452
+ const bpm = state.currentSong.bpm;
453
+ const beatInterval = 60000 / bpm;
454
+
455
+ if (state.currentTime >= state.nextHitTime) {
456
+ spawnHitObject();
457
+ state.nextHitTime = state.currentTime + beatInterval / difficultySettings.speed;
458
+ }
459
+
460
+ // Remove old hit objects
461
+ cleanupHitObjects();
462
+
463
+ // Continue loop
464
+ state.animationFrame = requestAnimationFrame(gameLoop);
465
+
466
+ // End game after 1 minute (demo)
467
+ if (state.currentTime >= 60000) {
468
+ endGame();
469
+ }
470
+ }
471
+
472
+ // Spawn hit object
473
+ function spawnHitObject() {
474
+ const gameWidth = elements.gameContainer.clientWidth;
475
+ const gameHeight = elements.gameContainer.clientHeight;
476
+
477
+ // Random position (avoid edges)
478
+ const x = Math.random() * (gameWidth - 160) + 80;
479
+ const y = Math.random() * (gameHeight - 200) + 80;
480
+
481
+ // Create hit circle
482
+ const hitCircle = document.createElement('div');
483
+ hitCircle.className = 'hit-circle';
484
+ hitCircle.style.left = `${x}px`;
485
+ hitCircle.style.top = `${y}px`;
486
+
487
+ // Set number (1-4)
488
+ const number = state.currentSong.pattern[Math.floor(Math.random() * state.currentSong.pattern.length)];
489
+ hitCircle.textContent = number;
490
+ hitCircle.dataset.number = number;
491
+
492
+ // Set timeout for auto-miss
493
+ const difficultySettings = difficulties[state.difficulty];
494
+ hitCircle.dataset.spawnTime = state.currentTime;
495
+
496
+ // Add to DOM
497
+ elements.gameContainer.appendChild(hitCircle);
498
+
499
+ // Animate in
500
+ setTimeout(() => {
501
+ hitCircle.classList.add('active');
502
+ }, 10);
503
+
504
+ // Add to state
505
+ state.hitObjects.push({
506
+ element: hitCircle,
507
+ spawnTime: state.currentTime,
508
+ hit: false
509
+ });
510
+
511
+ state.totalHits++;
512
+ }
513
+
514
+ // Clean up old hit objects
515
+ function cleanupHitObjects() {
516
+ const difficultySettings = difficulties[state.difficulty];
517
+ const missThreshold = difficultySettings.accuracyWindow * 2;
518
+
519
+ for (let i = state.hitObjects.length - 1; i >= 0; i--) {
520
+ const obj = state.hitObjects[i];
521
+ const age = state.currentTime - obj.spawnTime;
522
+
523
+ if (!obj.hit && age > missThreshold) {
524
+ // Missed this hit object
525
+ obj.element.classList.remove('active');
526
+ obj.element.classList.add('miss');
527
+ obj.hit = true;
528
+
529
+ // Show miss judgement
530
+ showJudgement('miss', obj.element);
531
+
532
+ // Reset combo
533
+ state.combo = 0;
534
+ elements.combo.textContent = '0';
535
+
536
+ // Remove after animation
537
+ setTimeout(() => {
538
+ obj.element.remove();
539
+ state.hitObjects.splice(i, 1);
540
+ }, 500);
541
+ } else if (obj.hit && age > 1000) {
542
+ // Remove hit objects after they've been judged
543
+ obj.element.remove();
544
+ state.hitObjects.splice(i, 1);
545
+ }
546
+ }
547
+ }
548
+
549
+ // Handle tap/click
550
+ function handleTap(e) {
551
+ if (!state.gameActive) return;
552
+
553
+ // Check if we hit a circle
554
+ const hitCircle = e.target.closest('.hit-circle');
555
+ if (hitCircle && hitCircle.classList.contains('active')) {
556
+ evaluateHit(hitCircle);
557
+ }
558
+ }
559
+
560
+ // Handle keyboard press
561
+ function handleKeyPress(e) {
562
+ if (!state.gameActive) return;
563
+
564
+ // Map keys 1-4 to hit objects
565
+ const key = parseInt(e.key);
566
+ if (key >= 1 && key <= 4) {
567
+ // Find the oldest active hit object with this number
568
+ const now = state.currentTime;
569
+ const difficultySettings = difficulties[state.difficulty];
570
+
571
+ for (let i = 0; i < state.hitObjects.length; i++) {
572
+ const obj = state.hitObjects[i];
573
+ if (!obj.hit &&
574
+ obj.element.dataset.number == key &&
575
+ obj.element.classList.contains('active')) {
576
+
577
+ const age = now - obj.spawnTime;
578
+ const windowSize = difficultySettings.accuracyWindow;
579
+
580
+ // Only hit if within timing window
581
+ if (Math.abs(age - 500) <= windowSize) {
582
+ evaluateHit(obj.element);
583
+ break;
584
+ }
585
+ }
586
+ }
587
+ }
588
+ }
589
+
590
+ // Evaluate hit accuracy
591
+ function evaluateHit(hitCircle) {
592
+ const now = state.currentTime;
593
+ const spawnTime = parseInt(hitCircle.dataset.spawnTime);
594
+ const age = now - spawnTime;
595
+ const difficultySettings = difficulties[state.difficulty];
596
+ const windowSize = difficultySettings.accuracyWindow;
597
+
598
+ // Calculate accuracy
599
+ const timeDiff = Math.abs(age - 500); // 500ms is perfect timing
600
+ let judgement = '';
601
+ let points = 0;
602
+
603
+ if (timeDiff <= windowSize * 0.3) {
604
+ judgement = 'perfect';
605
+ points = 300;
606
+ } else if (timeDiff <= windowSize * 0.7) {
607
+ judgement = 'good';
608
+ points = 100;
609
+ } else if (timeDiff <= windowSize) {
610
+ judgement = 'good';
611
+ points = 50;
612
+ } else {
613
+ judgement = 'miss';
614
+ points = 0;
615
+ }
616
+
617
+ // Update score and combo
618
+ if (judgement !== 'miss') {
619
+ state.score += points;
620
+ state.combo++;
621
+ state.hits++;
622
+
623
+ // Update UI
624
+ elements.score.textContent = state.score;
625
+ elements.combo.textContent = state.combo;
626
+ elements.accuracy.textContent = `${Math.round((state.hits / state.totalHits) * 100)}%`;
627
+
628
+ // Mark as hit
629
+ const objIndex = state.hitObjects.findIndex(obj => obj.element === hitCircle);
630
+ if (objIndex !== -1) {
631
+ state.hitObjects[objIndex].hit = true;
632
+ }
633
+
634
+ // Animate hit
635
+ hitCircle.classList.remove('active');
636
+ hitCircle.classList.add(judgement);
637
+
638
+ // Show judgement
639
+ showJudgement(judgement, hitCircle);
640
+
641
+ // Show combo if applicable
642
+ if (state.combo > 0 && state.combo % 10 === 0) {
643
+ showCombo(state.combo, hitCircle);
644
+ }
645
+
646
+ // Remove after animation
647
+ setTimeout(() => {
648
+ hitCircle.remove();
649
+ }, 500);
650
+ }
651
+ }
652
+
653
+ // Show judgement text
654
+ function showJudgement(judgement, element) {
655
+ const x = parseInt(element.style.left) + 40;
656
+ const y = parseInt(element.style.top) + 40;
657
+
658
+ const judgementEl = document.createElement('div');
659
+ judgementEl.className = `judgement ${judgement}`;
660
+ judgementEl.textContent =
661
+ judgement === 'perfect' ? '完璧!' :
662
+ judgement === 'good' ? '良い!' : 'ミス!';
663
+ judgementEl.style.left = `${x}px`;
664
+ judgementEl.style.top = `${y}px`;
665
+
666
+ elements.gameContainer.appendChild(judgementEl);
667
+
668
+ // Animate in
669
+ setTimeout(() => {
670
+ judgementEl.classList.add('show');
671
+ }, 10);
672
+
673
+ // Remove after animation
674
+ setTimeout(() => {
675
+ judgementEl.remove();
676
+ }, 1000);
677
+ }
678
+
679
+ // Show combo text
680
+ function showCombo(combo, element) {
681
+ const x = parseInt(element.style.left) + 40;
682
+ const y = parseInt(element.style.top) - 60;
683
+
684
+ const comboEl = document.createElement('div');
685
+ comboEl.className = 'combo-display';
686
+ comboEl.textContent = `${combo} コンボ!`;
687
+ comboEl.style.left = `${x}px`;
688
+ comboEl.style.top = `${y}px`;
689
+
690
+ elements.gameContainer.appendChild(comboEl);
691
+
692
+ // Animate in
693
+ setTimeout(() => {
694
+ comboEl.classList.add('show');
695
+ }, 10);
696
+
697
+ // Remove after animation
698
+ setTimeout(() => {
699
+ comboEl.remove();
700
+ }, 1000);
701
+ }
702
+
703
+ // End game
704
+ function endGame() {
705
+ state.gameActive = false;
706
+
707
+ // Cancel animation frame
708
+ if (state.animationFrame) {
709
+ cancelAnimationFrame(state.animationFrame);
710
+ state.animationFrame = null;
711
+ }
712
+
713
+ // Update buttons
714
+ elements.startBtn.disabled = false;
715
+ elements.pauseBtn.disabled = true;
716
+
717
+ // Show results
718
+ setTimeout(() => {
719
+ alert(`ゲーム終了!\nスコア: ${state.score}\nコンボ: ${state.combo}\n精度: ${Math.round((state.hits / state.totalHits) * 100)}%`);
720
+ }, 500);
721
+ }
722
+
723
+ // Initialize when DOM is loaded
724
+ document.addEventListener('DOMContentLoaded', init);
725
+ </script>
726
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Tingchenliang/tempo-game" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
727
+ </html>