Create a complete, single-file HTML game using Three.js called "Asteroid Intercept." The game should be a 3D space simulation where the player must defend a planet by launching interceptor missiles to destroy incoming asteroids.
Core Requirements:
Scene Setup:
Space Environment: Create a dark space background with a procedurally generated starfield (many small white THREE.Points).
The Planet: In the center of the scene, place a large, textured blue sphere representing the planet. It should rotate slowly on its Y-axis. Do not use external texture files; generate the texture procedurally or use vertex colors to create a convincing water/land effect.
Lighting: Use an AmbientLight for general visibility and a DirectionalLight to simulate a sun, casting light on the planet and other objects.
Camera: Use a PerspectiveCamera that can be controlled (pan, zoom, orbit) by the user via OrbitControls.
Gameplay Mechanics:
Asteroid Spawning: Every few seconds, a new asteroid (a brownish, irregularly shaped THREE.Mesh using IcosahedronGeometry with displaced vertices) should spawn at a random position outside the player's immediate view. Each asteroid should be given a random velocity vector that sends it on a collision course with the planet.
Player Aiming & Firing:
A targeting reticle (a simple 2D div or a 3D THREE.Sprite) should follow the user's mouse cursor across the 3D space.
When the player clicks, launch an "interceptor missile" from a point near the camera. The missile should be a small, bright, elongated shape (e.g., a thin cylinder or capsule with an emissive material).
The missile's velocity should be high, and its direction should be aimed directly at the 3D position of the targeting reticle at the moment of the click.
Physics and Collision:
All objects (asteroids, missiles) must move each frame according to their velocity.
Collision Detection: In the game loop, you must continuously check for collisions. A collision occurs when an interceptor missile gets within a certain radius of an asteroid.
Collision Consequence: When a missile hits an asteroid, both the missile and the asteroid should be removed from the scene. Create a small, brief "explosion" effect at the point of impact using THREE.Points with random velocities.
Game State & UI:
Scoring: The player gets one point for each asteroid destroyed. Display the score in a simple HTML overlay .
Losing Condition: If an asteroid collides with the planet, the game is over.
Game Over Screen: When the game ends, display a "Game Over" message and the final score in a prominent overlay. Include a "Restart" button that resets the scene, score, and game state.
Instructions: Display brief instructions on the screen (e.g., "Use mouse to aim, click to fire. Defend the planet!").
Technical Constraints:
Single File: The entire game—HTML, CSS, and JavaScript—must be contained within a single .html file.
No External Libraries (except Three.js): You must import Three.js and OrbitControls from a reliable CDN (like unpkg or jsdelivr). No other external JS libraries are allowed.
Performance: The code should be reasonably optimized. Ensure objects are properly removed from the scene and their geometries/materials are disposed of to prevent memory leaks.
Aesthetics: The game should be visually appealing. Use color, lighting, and particle effects to create an engaging experience.
Code Quality: The JavaScript code must be well-commented, explaining the logic for the game loop, physics, spawning, and collision detection.