Spaces:
Running
Running
Download index.html from sergiomcfly/anycoder-56d71fdb: direct link, hf CLI and curl.
- Browser
- Download file 31.5 kB
-
https://huggingface.co/spaces/sergiomcfly/anycoder-56d71fdb/resolve/main/index.html
- Command line
-
hf download hf://spaces/sergiomcfly/anycoder-56d71fdb/index.html
-
curl -L -o index.html https://huggingface.co/spaces/sergiomcfly/anycoder-56d71fdb/resolve/main/index.html
31.5 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Cheers 3D - Clink & Celebrate!</title> | |
| <link href="https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;900&family=Space+Grotesk:wght@300;400;600&display=swap" rel="stylesheet"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script> | |
| <style> | |
| :root { | |
| --bg: #0a0a12; | |
| --fg: #f4f0e8; | |
| --muted: #6b6b7b; | |
| --accent: #ffd700; | |
| --accent-glow: rgba(255, 215, 0, 0.4); | |
| --card: rgba(255, 255, 255, 0.05); | |
| --border: rgba(255, 255, 255, 0.1); | |
| --glass: rgba(200, 220, 255, 0.15); | |
| --liquid: rgba(255, 200, 100, 0.6); | |
| } | |
| * { | |
| margin: 0; | |
| padding: 0; | |
| box-sizing: border-box; | |
| } | |
| body { | |
| font-family: 'Space Grotesk', sans-serif; | |
| background: var(--bg); | |
| color: var(--fg); | |
| min-height: 100vh; | |
| overflow: hidden; | |
| position: relative; | |
| } | |
| #canvas-container { | |
| position: fixed; | |
| top: 0; | |
| left: 0; | |
| width: 100%; | |
| height: 100%; | |
| z-index: 1; | |
| } | |
| .ui-overlay { | |
| position: fixed; | |
| z-index: 10; | |
| pointer-events: none; | |
| } | |
| .header { | |
| top: 0; | |
| left: 0; | |
| right: 0; | |
| padding: 1.5rem 2rem; | |
| display: flex; | |
| justify-content: space-between; | |
| align-items: center; | |
| background: linear-gradient(to bottom, rgba(10, 10, 18, 0.9), transparent); | |
| } | |
| .logo { | |
| font-family: 'Playfair Display', serif; | |
| font-size: clamp(1.5rem, 4vw, 2.5rem); | |
| font-weight: 900; | |
| background: linear-gradient(135deg, var(--accent), #fff8dc); | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| background-clip: text; | |
| letter-spacing: 0.05em; | |
| } | |
| .logo-link { | |
| text-decoration: none; | |
| pointer-events: auto; | |
| } | |
| .built-with { | |
| font-size: 0.7rem; | |
| color: var(--muted); | |
| text-decoration: none; | |
| pointer-events: auto; | |
| transition: color 0.3s ease; | |
| } | |
| .built-with:hover { | |
| color: var(--accent); | |
| } | |
| .score-panel { | |
| top: 50%; | |
| right: 2rem; | |
| transform: translateY(-50%); | |
| text-align: right; | |
| } | |
| .score-label { | |
| font-size: 0.75rem; | |
| text-transform: uppercase; | |
| letter-spacing: 0.2em; | |
| color: var(--muted); | |
| margin-bottom: 0.5rem; | |
| } | |
| .score-value { | |
| font-family: 'Playfair Display', serif; | |
| font-size: clamp(3rem, 8vw, 6rem); | |
| font-weight: 900; | |
| color: var(--accent); | |
| line-height: 1; | |
| text-shadow: 0 0 40px var(--accent-glow); | |
| } | |
| .combo-display { | |
| margin-top: 1rem; | |
| font-size: 1rem; | |
| color: var(--fg); | |
| opacity: 0; | |
| transform: translateY(10px); | |
| transition: all 0.3s ease; | |
| } | |
| .combo-display.active { | |
| opacity: 1; | |
| transform: translateY(0); | |
| } | |
| .instructions { | |
| bottom: 2rem; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| text-align: center; | |
| background: var(--card); | |
| backdrop-filter: blur(20px); | |
| border: 1px solid var(--border); | |
| border-radius: 1rem; | |
| padding: 1rem 2rem; | |
| pointer-events: auto; | |
| } | |
| .instructions h2 { | |
| font-family: 'Playfair Display', serif; | |
| font-size: 1.25rem; | |
| margin-bottom: 0.5rem; | |
| color: var(--accent); | |
| } | |
| .instructions p { | |
| font-size: 0.875rem; | |
| color: var(--muted); | |
| max-width: 300px; | |
| } | |
| .cheers-text { | |
| position: fixed; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%) scale(0); | |
| font-family: 'Playfair Display', serif; | |
| font-size: clamp(3rem, 15vw, 8rem); | |
| font-weight: 900; | |
| color: var(--accent); | |
| text-shadow: 0 0 60px var(--accent-glow), 0 0 120px var(--accent-glow); | |
| z-index: 20; | |
| pointer-events: none; | |
| opacity: 0; | |
| transition: all 0.1s ease; | |
| } | |
| .cheers-text.show { | |
| animation: cheersPop 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; | |
| } | |
| @keyframes cheersPop { | |
| 0% { | |
| transform: translate(-50%, -50%) scale(0) rotate(-10deg); | |
| opacity: 0; | |
| } | |
| 50% { | |
| transform: translate(-50%, -50%) scale(1.2) rotate(5deg); | |
| opacity: 1; | |
| } | |
| 100% { | |
| transform: translate(-50%, -50%) scale(1) rotate(0deg); | |
| opacity: 0; | |
| } | |
| } | |
| .glass-selector { | |
| bottom: 8rem; | |
| left: 50%; | |
| transform: translateX(-50%); | |
| display: flex; | |
| gap: 1rem; | |
| pointer-events: auto; | |
| } | |
| .glass-btn { | |
| width: 60px; | |
| height: 60px; | |
| border-radius: 50%; | |
| border: 2px solid var(--border); | |
| background: var(--card); | |
| backdrop-filter: blur(10px); | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| display: flex; | |
| align-items: center; | |
| justify-content: center; | |
| color: var(--fg); | |
| } | |
| .glass-btn:hover { | |
| border-color: var(--accent); | |
| transform: scale(1.1); | |
| } | |
| .glass-btn.active { | |
| border-color: var(--accent); | |
| background: rgba(255, 215, 0, 0.2); | |
| box-shadow: 0 0 20px var(--accent-glow); | |
| } | |
| .glass-btn svg { | |
| width: 28px; | |
| height: 28px; | |
| } | |
| .ambient-orb { | |
| position: fixed; | |
| width: 400px; | |
| height: 400px; | |
| border-radius: 50%; | |
| background: radial-gradient(circle, var(--accent-glow), transparent 70%); | |
| filter: blur(80px); | |
| pointer-events: none; | |
| z-index: 0; | |
| opacity: 0.3; | |
| animation: orbFloat 8s ease-in-out infinite; | |
| } | |
| .orb-1 { | |
| top: -100px; | |
| left: -100px; | |
| } | |
| .orb-2 { | |
| bottom: -100px; | |
| right: -100px; | |
| background: radial-gradient(circle, rgba(255, 100, 150, 0.3), transparent 70%); | |
| animation-delay: -4s; | |
| } | |
| @keyframes orbFloat { | |
| 0%, 100% { transform: translate(0, 0); } | |
| 50% { transform: translate(30px, 30px); } | |
| } | |
| .streak-bar { | |
| position: fixed; | |
| bottom: 0; | |
| left: 0; | |
| right: 0; | |
| height: 4px; | |
| background: var(--border); | |
| z-index: 15; | |
| } | |
| .streak-fill { | |
| height: 100%; | |
| background: linear-gradient(90deg, var(--accent), #ff6b6b); | |
| width: 0%; | |
| transition: width 0.3s ease; | |
| box-shadow: 0 0 20px var(--accent); | |
| } | |
| @media (max-width: 768px) { | |
| .header { | |
| padding: 1rem; | |
| } | |
| .score-panel { | |
| right: 1rem; | |
| } | |
| .instructions { | |
| left: 1rem; | |
| right: 1rem; | |
| transform: none; | |
| padding: 0.75rem 1rem; | |
| } | |
| .glass-selector { | |
| bottom: 6rem; | |
| } | |
| .glass-btn { | |
| width: 50px; | |
| height: 50px; | |
| } | |
| } | |
| @media (prefers-reduced-motion: reduce) { | |
| *, *::before, *::after { | |
| animation-duration: 0.01ms ; | |
| animation-iteration-count: 1 ; | |
| transition-duration: 0.01ms ; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="ambient-orb orb-1"></div> | |
| <div class="ambient-orb orb-2"></div> | |
| <div id="canvas-container"></div> | |
| <header class="ui-overlay header"> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" class="built-with" target="_blank" rel="noopener">Built with anycoder</a> | |
| <div class="logo">CHEERS 3D</div> | |
| <div style="width: 100px;"></div> | |
| </header> | |
| <div class="ui-overlay score-panel"> | |
| <div class="score-label">Cheers Score</div> | |
| <div class="score-value" id="score">0</div> | |
| <div class="combo-display" id="combo">Combo x1</div> | |
| </div> | |
| <div class="ui-overlay instructions"> | |
| <h2>Click & Drag to Clink!</h2> | |
| <p>Drag glasses together to cheers. Chain multiple clinks for combo points!</p> | |
| </div> | |
| <div class="ui-overlay glass-selector"> | |
| <button class="glass-btn active" data-type="champagne" aria-label="Champagne glass"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | |
| <path d="M8 22h8M12 22v-4M12 18c-4 0-6-3-6-6V2h12v10c0 3-2 6-6 6z"/> | |
| </svg> | |
| </button> | |
| <button class="glass-btn" data-type="wine" aria-label="Wine glass"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | |
| <path d="M8 22h8M12 22v-4M12 18c-3 0-4-2-4-5V2h8v11c0 3-1 5-4 5z"/> | |
| </svg> | |
| </button> | |
| <button class="glass-btn" data-type="beer" aria-label="Beer mug"> | |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | |
| <path d="M17 8h2a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-2M6 8h11v10a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8zM6 8V6a2 2 0 0 1 2-2h7a2 2 0 0 1 2 2v2"/> | |
| </svg> | |
| </button> | |
| </div> | |
| <div class="streak-bar"> | |
| <div class="streak-fill" id="streakFill"></div> | |
| </div> | |
| <div class="cheers-text" id="cheersText">CHEERS!</div> | |
| <script> | |
| // Game State | |
| const state = { | |
| score: 0, | |
| combo: 0, | |
| lastClinkTime: 0, | |
| streak: 0, | |
| maxStreak: 100, | |
| selectedGlass: 'champagne' | |
| }; | |
| // Three.js Setup | |
| let scene, camera, renderer, glasses = [], particles = [], confetti = []; | |
| let raycaster, mouse, selectedObject = null, offset = new THREE.Vector3(); | |
| let isDragging = false; | |
| function init() { | |
| // Scene | |
| scene = new THREE.Scene(); | |
| scene.fog = new THREE.FogExp2(0x0a0a12, 0.02); | |
| // Camera | |
| camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 0.1, 1000); | |
| camera.position.set(0, 3, 8); | |
| camera.lookAt(0, 1, 0); | |
| // Renderer | |
| renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true }); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); | |
| renderer.shadowMap.enabled = true; | |
| renderer.shadowMap.type = THREE.PCFSoftShadowMap; | |
| document.getElementById('canvas-container').appendChild(renderer.domElement); | |
| // Lights | |
| const ambientLight = new THREE.AmbientLight(0x404060, 0.5); | |
| scene.add(ambientLight); | |
| const mainLight = new THREE.DirectionalLight(0xffffff, 1); | |
| mainLight.position.set(5, 10, 5); | |
| mainLight.castShadow = true; | |
| mainLight.shadow.mapSize.width = 2048; | |
| mainLight.shadow.mapSize.height = 2048; | |
| scene.add(mainLight); | |
| const accentLight = new THREE.PointLight(0xffd700, 1, 20); | |
| accentLight.position.set(0, 5, 0); | |
| scene.add(accentLight); | |
| const rimLight = new THREE.PointLight(0xff6b6b, 0.5, 15); | |
| rimLight.position.set(-5, 3, -5); | |
| scene.add(rimLight); | |
| // Floor | |
| const floorGeometry = new THREE.CircleGeometry(10, 64); | |
| const floorMaterial = new THREE.MeshStandardMaterial({ | |
| color: 0x1a1a2e, | |
| roughness: 0.8, | |
| metalness: 0.2 | |
| }); | |
| const floor = new THREE.Mesh(floorGeometry, floorMaterial); | |
| floor.rotation.x = -Math.PI / 2; | |
| floor.receiveShadow = true; | |
| scene.add(floor); | |
| // Table | |
| const tableGeometry = new THREE.CylinderGeometry(3, 3.2, 0.3, 32); | |
| const tableMaterial = new THREE.MeshStandardMaterial({ | |
| color: 0x2d1810, | |
| roughness: 0.4, | |
| metalness: 0.1 | |
| }); | |
| const table = new THREE.Mesh(tableGeometry, tableMaterial); | |
| table.position.y = 0.15; | |
| table.receiveShadow = true; | |
| table.castShadow = true; | |
| scene.add(table); | |
| // Create glasses | |
| createGlasses(); | |
| // Raycaster for interaction | |
| raycaster = new THREE.Raycaster(); | |
| mouse = new THREE.Vector2(); | |
| // Event Listeners | |
| setupEventListeners(); | |
| // Start animation | |
| animate(); | |
| } | |
| function createGlassGeometry(type) { | |
| const group = new THREE.Group(); | |
| // Glass material | |
| const glassMaterial = new THREE.MeshPhysicalMaterial({ | |
| color: 0xffffff, | |
| transparent: true, | |
| opacity: 0.3, | |
| roughness: 0.1, | |
| metalness: 0, | |
| transmission: 0.9, | |
| thickness: 0.5 | |
| }); | |
| // Liquid material | |
| const liquidMaterial = new THREE.MeshPhysicalMaterial({ | |
| color: type === 'beer' ? 0xd4a03c : 0xffd700, | |
| transparent: true, | |
| opacity: 0.7, | |
| roughness: 0.2, | |
| metalness: 0.1 | |
| }); | |
| if (type === 'champagne') { | |
| // Flute shape | |
| const bowlGeometry = new THREE.LatheGeometry([ | |
| new THREE.Vector2(0, 0), | |
| new THREE.Vector2(0.15, 0), | |
| new THREE.Vector2(0.4, 0.8), | |
| new THREE.Vector2(0.35, 1.5), | |
| new THREE.Vector2(0.25, 2), | |
| new THREE.Vector2(0.15, 2.2), | |
| new THREE.Vector2(0, 2.2) | |
| ], 32); | |
| const bowl = new THREE.Mesh(bowlGeometry, glassMaterial); | |
| group.add(bowl); | |
| // Liquid | |
| const liquidGeometry = new THREE.LatheGeometry([ | |
| new THREE.Vector2(0, 0.1), | |
| new THREE.Vector2(0.35, 0.8), | |
| new THREE.Vector2(0.32, 1.3), | |
| new THREE.Vector2(0.2, 1.8), | |
| new THREE.Vector2(0, 1.8) | |
| ], 32); | |
| const liquid = new THREE.Mesh(liquidGeometry, liquidMaterial); | |
| group.add(liquid); | |
| // Stem | |
| const stemGeometry = new THREE.CylinderGeometry(0.05, 0.05, 1, 16); | |
| const stem = new THREE.Mesh(stemGeometry, glassMaterial); | |
| stem.position.y = -0.5; | |
| group.add(stem); | |
| // Base | |
| const baseGeometry = new THREE.CylinderGeometry(0.25, 0.3, 0.1, 32); | |
| const base = new THREE.Mesh(baseGeometry, glassMaterial); | |
| base.position.y = -1; | |
| group.add(base); | |
| } else if (type === 'wine') { | |
| // Wine glass shape | |
| const bowlGeometry = new THREE.LatheGeometry([ | |
| new THREE.Vector2(0, 0), | |
| new THREE.Vector2(0.12, 0), | |
| new THREE.Vector2(0.5, 0.3), | |
| new THREE.Vector2(0.55, 0.6), | |
| new THREE.Vector2(0.4, 1.2), | |
| new THREE.Vector2(0.25, 1.6), | |
| new THREE.Vector2(0.12, 1.7), | |
| new THREE.Vector2(0, 1.7) | |
| ], 32); | |
| const bowl = new THREE.Mesh(bowlGeometry, glassMaterial); | |
| group.add(bowl); | |
| // Liquid | |
| const liquidGeometry = new THREE.LatheGeometry([ | |
| new THREE.Vector2(0, 0.1), | |
| new THREE.Vector2(0.45, 0.35), | |
| new THREE.Vector2(0.5, 0.5), | |
| new THREE.Vector2(0.35, 1), | |
| new THREE.Vector2(0.2, 1.3), | |
| new THREE.Vector2(0, 1.3) | |
| ], 32); | |
| const liquid = new THREE.Mesh(liquidGeometry, new THREE.MeshPhysicalMaterial({ | |
| color: 0x722f37, | |
| transparent: true, | |
| opacity: 0.8, | |
| roughness: 0.2 | |
| })); | |
| group.add(liquid); | |
| // Stem | |
| const stemGeometry = new THREE.CylinderGeometry(0.04, 0.04, 1.2, 16); | |
| const stem = new THREE.Mesh(stemGeometry, glassMaterial); | |
| stem.position.y = -0.6; | |
| group.add(stem); | |
| // Base | |
| const baseGeometry = new THREE.CylinderGeometry(0.22, 0.26, 0.08, 32); | |
| const base = new THREE.Mesh(baseGeometry, glassMaterial); | |
| base.position.y = -1.2; | |
| group.add(base); | |
| } else if (type === 'beer') { | |
| // Beer mug | |
| const mugGeometry = new THREE.CylinderGeometry(0.35, 0.32, 1.5, 32, 1, true); | |
| const mug = new THREE.Mesh(mugGeometry, glassMaterial); | |
| mug.position.y = 0.75; | |
| group.add(mug); | |
| // Bottom | |
| const bottomGeometry = new THREE.CylinderGeometry(0.32, 0.32, 0.08, 32); | |
| const bottom = new THREE.Mesh(bottomGeometry, glassMaterial); | |
| bottom.position.y = 0.04; | |
| group.add(bottom); | |
| // Liquid | |
| const liquidGeometry = new THREE.CylinderGeometry(0.32, 0.29, 1.2, 32); | |
| const liquid = new THREE.Mesh(liquidGeometry, liquidMaterial); | |
| liquid.position.y = 0.7; | |
| group.add(liquid); | |
| // Foam | |
| const foamGeometry = new THREE.SphereGeometry(0.33, 32, 16, 0, Math.PI * 2, 0, Math.PI / 2); | |
| const foamMaterial = new THREE.MeshStandardMaterial({ | |
| color: 0xfff8dc, | |
| roughness: 0.8 | |
| }); | |
| const foam = new THREE.Mesh(foamGeometry, foamMaterial); | |
| foam.position.y = 1.35; | |
| foam.scale.y = 0.5; | |
| group.add(foam); | |
| // Handle | |
| const handleGeometry = new THREE.TorusGeometry(0.2, 0.04, 8, 16, Math.PI); | |
| const handle = new THREE.Mesh(handleGeometry, glassMaterial); | |
| handle.position.set(0.38, 0.75, 0); | |
| handle.rotation.z = Math.PI / 2; | |
| group.add(handle); | |
| } | |
| group.castShadow = true; | |
| group.traverse((child) => { | |
| if (child.isMesh) { | |
| child.castShadow = true; | |
| child.receiveShadow = true; | |
| } | |
| }); | |
| return group; | |
| } | |
| function createGlasses() { | |
| // Clear existing glasses | |
| glasses.forEach(glass => scene.remove(glass)); | |
| glasses = []; | |
| // Create two glasses | |
| const positions = [ | |
| { x: -1.5, y: 0.3, z: 0 }, | |
| { x: 1.5, y: 0.3, z: 0 } | |
| ]; | |
| positions.forEach((pos, index) => { | |
| const glass = createGlassGeometry(state.selectedGlass); | |
| glass.position.set(pos.x, pos.y, pos.z); | |
| glass.userData = { | |
| index: index, | |
| originalPos: { ...pos }, | |
| velocity: new THREE.Vector3() | |
| }; | |
| scene.add(glass); | |
| glasses.push(glass); | |
| }); | |
| } | |
| function createBubbles(position) { | |
| for (let i = 0; i < 20; i++) { | |
| const geometry = new THREE.SphereGeometry(Math.random() * 0.05 + 0.02, 8, 8); | |
| const material = new THREE.MeshBasicMaterial({ | |
| color: 0xffffff, | |
| transparent: true, | |
| opacity: 0.6 | |
| }); | |
| const bubble = new THREE.Mesh(geometry, material); | |
| bubble.position.copy(position); | |
| bubble.position.y += 1; | |
| bubble.position.x += (Math.random() - 0.5) * 0.5; | |
| bubble.position.z += (Math.random() - 0.5) * 0.5; | |
| bubble.userData = { | |
| velocity: new THREE.Vector3( | |
| (Math.random() - 0.5) * 0.02, | |
| Math.random() * 0.05 + 0.02, | |
| (Math.random() - 0.5) * 0.02 | |
| ), | |
| life: 1 | |
| }; | |
| scene.add(bubble); | |
| particles.push(bubble); | |
| } | |
| } | |
| function createConfetti() { | |
| const colors = [0xffd700, 0xff6b6b, 0x4ecdc4, 0xff69b4, 0x87ceeb]; | |
| for (let i = 0; i < 50; i++) { | |
| const geometry = new THREE.BoxGeometry(0.05, 0.05, 0.01); | |
| const material = new THREE.MeshBasicMaterial({ | |
| color: colors[Math.floor(Math.random() * colors.length)] | |
| }); | |
| const confetto = new THREE.Mesh(geometry, material); | |
| confetto.position.set( | |
| (Math.random() - 0.5) * 2, | |
| 5 + Math.random() * 2, | |
| (Math.random() - 0.5) * 2 | |
| ); | |
| confetto.rotation.set( | |
| Math.random() * Math.PI, | |
| Math.random() * Math.PI, | |
| Math.random() * Math.PI | |
| ); | |
| confetto.userData = { | |
| velocity: new THREE.Vector3( | |
| (Math.random() - 0.5) * 0.05, | |
| -0.05 - Math.random() * 0.05, | |
| (Math.random() - 0.5) * 0.05 | |
| ), | |
| rotationSpeed: new THREE.Vector3( | |
| Math.random() * 0.1, | |
| Math.random() * 0.1, | |
| Math.random() * 0.1 | |
| ), | |
| life: 1 | |
| }; | |
| scene.add(confetto); | |
| confetti.push(confetto); | |
| } | |
| } | |
| function checkCollision() { | |
| if (glasses.length < 2) return false; | |
| const glass1 = glasses[0]; | |
| const glass2 = glasses[1]; | |
| const distance = glass1.position.distanceTo(glass2.position); | |
| return distance < 0.8; | |
| } | |
| function handleClink() { | |
| const now = Date.now(); | |
| const timeSinceLastClink = now - state.lastClinkTime; | |
| if (timeSinceLastClink < 500) return; // Prevent spam | |
| state.lastClinkTime = now; | |
| state.combo = timeSinceLastClink < 2000 ? state.combo + 1 : 1; | |
| state.streak = Math.min(state.streak + 10, state.maxStreak); | |
| const points = 100 * state.combo; | |
| state.score += points; | |
| updateUI(); | |
| showCheersText(); | |
| createBubbles(glasses[0].position); | |
| createBubbles(glasses[1].position); | |
| createConfetti(); | |
| // Add impulse to glasses | |
| glasses.forEach(glass => { | |
| glass.userData.velocity.x = (Math.random() - 0.5) * 0.1; | |
| glass.userData.velocity.z = (Math.random() - 0.5) * 0.1; | |
| }); | |
| } | |
| function updateUI() { | |
| document.getElementById('score').textContent = state.score; | |
| document.getElementById('streakFill').style.width = `${state.streak}%`; | |
| const comboDisplay = document.getElementById('combo'); | |
| if (state.combo > 1) { | |
| comboDisplay.textContent = `Combo x${state.combo}`; | |
| comboDisplay.classList.add('active'); | |
| } else { | |
| comboDisplay.classList.remove('active'); | |
| } | |
| } | |
| function showCheersText() { | |
| const cheersText = document.getElementById('cheersText'); | |
| cheersText.classList.remove('show'); | |
| void cheersText.offsetWidth; // Trigger reflow | |
| cheersText.classList.add('show'); | |
| } | |
| function setupEventListeners() { | |
| const canvas = renderer.domElement; | |
| // Mouse events | |
| canvas.addEventListener('mousedown', onMouseDown); | |
| canvas.addEventListener('mousemove', onMouseMove); | |
| canvas.addEventListener('mouseup', onMouseUp); | |
| // Touch events | |
| canvas.addEventListener('touchstart', onTouchStart, { passive: false }); | |
| canvas.addEventListener('touchmove', onTouchMove, { passive: false }); | |
| canvas.addEventListener('touchend', onTouchEnd); | |
| // Glass selector | |
| document.querySelectorAll('.glass-btn').forEach(btn => { | |
| btn.addEventListener('click', () => { | |
| document.querySelectorAll('.glass-btn').forEach(b => b.classList.remove('active')); | |
| btn.classList.add('active'); | |
| state.selectedGlass = btn.dataset.type; | |
| createGlasses(); | |
| }); | |
| }); | |
| // Resize | |
| window.addEventListener('resize', onResize); | |
| } | |
| function getMousePosition(event) { | |
| const rect = renderer.domElement.getBoundingClientRect(); | |
| mouse.x = ((event.clientX - rect.left) / rect.width) * 2 - 1; | |
| mouse.y = -((event.clientY - rect.top) / rect.height) * 2 + 1; | |
| } | |
| function onMouseDown(event) { | |
| getMousePosition(event); | |
| raycaster.setFromCamera(mouse, camera); | |
| const intersects = raycaster.intersectObjects(glasses, true); | |
| if (intersects.length > 0) { | |
| isDragging = true; | |
| let obj = intersects[0].object; | |
| while (obj.parent && !glasses.includes(obj)) { | |
| obj = obj.parent; | |
| } | |
| selectedObject = obj; | |
| renderer.domElement.style.cursor = 'grabbing'; | |
| } | |
| } | |
| function onMouseMove(event) { | |
| if (!isDragging || !selectedObject) return; | |
| getMousePosition(event); | |
| raycaster.setFromCamera(mouse, camera); | |
| const plane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0); | |
| const point = new THREE.Vector3(); | |
| raycaster.ray.intersectPlane(plane, point); | |
| if (point) { | |
| selectedObject.position.x = point.x; | |
| selectedObject.position.z = point.z; | |
| // Check for collision | |
| if (checkCollision()) { | |
| handleClink(); | |
| } | |
| } | |
| } | |
| function onMouseUp() { | |
| isDragging = false; | |
| selectedObject = null; | |
| renderer.domElement.style.cursor = 'grab'; | |
| } | |
| function onTouchStart(event) { | |
| event.preventDefault(); | |
| if (event.touches.length === 1) { | |
| const touch = event.touches[0]; | |
| onMouseDown({ clientX: touch.clientX, clientY: touch.clientY }); | |
| } | |
| } | |
| function onTouchMove(event) { | |
| event.preventDefault(); | |
| if (event.touches.length === 1) { | |
| const touch = event.touches[0]; | |
| onMouseMove({ clientX: touch.clientX, clientY: touch.clientY }); | |
| } | |
| } | |
| function onTouchEnd() { | |
| onMouseUp(); | |
| } | |
| function onResize() { | |
| camera.aspect = window.innerWidth / window.innerHeight; | |
| camera.updateProjectionMatrix(); | |
| renderer.setSize(window.innerWidth, window.innerHeight); | |
| } | |
| function animate() { | |
| requestAnimationFrame(animate); | |
| // Update particles | |
| particles = particles.filter(particle => { | |
| particle.position.add(particle.userData.velocity); | |
| particle.userData.life -= 0.02; | |
| particle.material.opacity = particle.userData.life * 0.6; | |
| if (particle.userData.life <= 0) { | |
| scene.remove(particle); | |
| return false; | |
| } | |
| return true; | |
| }); | |
| // Update confetti | |
| confetti = confetti.filter(confetto => { | |
| confetto.position.add(confetto.userData.velocity); | |
| confetto.rotation.x += confetto.userData.rotationSpeed.x; | |
| confetto.rotation.y += confetto.userData.rotationSpeed.y; | |
| confetto.userData.life -= 0.01; | |
| if (confetto.position.y < 0 || confetto.userData.life <= 0) { | |
| scene.remove(confetto); | |
| return false; | |
| } | |
| return true; | |
| }); | |
| // Glass physics | |
| glasses.forEach(glass => { | |
| if (!isDragging || glass !== selectedObject) { | |
| // Apply velocity | |
| glass.position.add(glass.userData.velocity); | |
| // Friction | |
| glass.userData.velocity.multiplyScalar(0.95); | |
| // Spring back to original position | |
| const dx = glass.userData.originalPos.x - glass.position.x; | |
| const dz = glass.userData.originalPos.z - glass.position.z; | |
| glass.userData.velocity.x += dx * 0.02; | |
| glass.userData.velocity.z += dz * 0.02; | |
| // Wobble animation | |
| glass.rotation.z = Math.sin(Date.now() * 0.003 + glass.userData.index) * 0.02; | |
| glass.rotation.x = Math.cos(Date.now() * 0.002 + glass.userData.index) * 0.01; | |
| } | |
| }); | |
| // Decay streak | |
| if (Date.now() - state.lastClinkTime > 1000) { | |
| state.streak = Math.max(0, state.streak - 0.5); | |
| document.getElementById('streakFill').style.width = `${state.streak}%`; | |
| } | |
| // Decay combo | |
| if (Date.now() - state.lastClinkTime > 2000 && state.combo > 0) { | |
| state.combo = 0; | |
| document.getElementById('combo').classList.remove('active'); | |
| } | |
| renderer.render(scene, camera); | |
| } | |
| // Initialize | |
| init(); | |
| </script> | |
| </body> | |
| </html> |