Create a high-energy, arcade-style "beat saber" meets "fruit ninja" experience in a cosmic setting. Users slice through incoming cosmic objects (crystals, meteors, stars) using their hands as lightsabers, building combos and defeating bosses in a visually stunning 3D environment.
- Entry: User switches to Cosmic Slash mode. The environment transitions to a deep space scene with a procedural starfield and neon lighting.
- Gameplay Loop:
- Cosmic objects (crystals, meteors, etc.) spawn in the distance and fly toward the screen.
- User moves hands to create glowing, energy-ribbon trails.
- Slicing objects triggers explosions, sound effects, and floating score popups.
- Consecutive hits build a "Combo" multiplier, increasing score.
- Progression:
- As score increases, the game levels up (speed and spawn rate increase).
- Boss Encounters: Periodically, a massive "Boss" object appears. The user must slash it repeatedly to defeat it before it passes.
- Power-ups: Special "POW" mechanics allow for screen-clearing attacks (e.g., two-hand laser beam).
- Feedback:
- Visuals: Bloom, screen shake, particle explosions, dynamic lighting.
- UI: HUD shows Score, Combo, Level, and Boss Health.
The architecture follows a controller-based pattern, orchestrating Three.js rendering, physics, and game logic.
graph TD
App[App.ts] --> Controller[CosmicSlashController]
subgraph "Core Systems"
Controller --> Env[CosmicEnvironment]
Controller --> Pool[ObjectPoolManager]
Controller --> Collision[CollisionDetector]
Controller --> Asset[CosmicAssetLibrary]
end
subgraph "Input & Visuals"
Controller --> HandTracker["HandTracker (Shared)"]
Controller --> Trail[HandTrailRenderer]
Controller --> Effects[Visual Effects]
end
subgraph "Game Logic"
Controller --> Score[ScoreManager]
Controller --> Boss[BossOverlay]
Controller --> Pow[PowManager]
end
Purpose: The central brain of the mode. Responsibilities:
- Manages the Three.js scene, camera, and renderer.
- Runs the main game loop (update & render).
- Coordinates object spawning via
ObjectPoolManager. - Feeds hand data to
HandTrailRendererandCollisionDetector. - Manages game state (Playing, Paused, Boss Fight).
Purpose: Renders high-fidelity, lightsaber-like trails. Key Tech:
- Custom Shaders:
ribbonVertexShaderandribbonFragmentShaderfor a glowing core + aura effect. - Smoothing: Uses
OneEuroFilterto reduce jitter and latency from hand tracking. - Sparkles: GPU-accelerated particle system for trail embellishments.
- Logic: Tracks hands by position continuity (nearest-neighbor) rather than unreliable "Left/Right" labels.
Purpose: Handles interaction between hands and objects. Key Tech:
- Screen-Space Detection: Projects 3D object positions to 2D screen coordinates for reliable hit testing against hand trails.
- Optimization: Uses a cooldown system to prevent double-hits on the same frame.
- Depth Check: Ensures objects are only sliceable when they are close to the "screen plane".
Purpose: High-performance object management. Key Tech:
- Pre-allocates
CosmicObjectinstances to avoid Garbage Collection spikes. - Manages lifecycle:
Pooled->Active->Sliced/Missed->Pooled. - Supports multiple object types (Crystal, Meteor, Star, etc.) with different visual properties.
- Detection: Raycasting is too expensive/complex for this arcade feel. Instead, we project the 3D object's center to 2D screen space.
- Hit Test: If a hand trail segment intersects the object's 2D bounding circle and the object is within a specific Z-depth range, a hit is registered.
- Velocity: Slicing requires a minimum hand velocity to register, preventing accidental "touches".
- Trigger: Occurs after a set number of levels or score threshold.
- Phases:
- Warning:
BossWarningOverlayflashes, music changes. - Active: Boss object (massive scale) moves slowly across the screen.
- Combat: User must slash the boss multiple times (HP system) to deplete its health bar (
BossHud). - Resolution: Boss explodes (massive particle effect) or escapes (damage penalty).
- Warning:
- Mechanic: A "POW" meter fills up during gameplay.
- Activation: Specific gestures (e.g., holding hands together) trigger the
PowManager. - Effect:
PowLaserEffectfires a continuous beam or clears all enemies on screen.
- Base Score: Points per object type.
- Combo System: Consecutive hits within a time window (
comboWindowMs) increase the multiplier. Missing an object resets the combo. - Visuals:
FloatingScoreEffectspawns 3D text at the impact site.
- Tone Mapping:
ACESFilmicToneMappingfor cinematic contrast and saturation. - Color Space:
SRGBColorSpacefor accurate color reproduction. - Post-Processing:
UnrealBloomPass(viaPostProcessingManager) for the signature neon glow.
- Background: A procedural starfield generated on a HTML5 Canvas and mapped to a sphere (
CosmicEnvironment.ts). - Lighting: Dynamic setup with Ambient, Point, and Rim lights to accentuate object materials.
- SliceEffect: Generates a planar mesh at the slice angle to simulate the object being cut in half.
- ScreenFlashEffect: Full-screen flash on impact or level up.
- Particles: GPU-based particle systems for explosions and trail sparkles.
- Object Pooling: Essential for maintaining 60 FPS with frequent object spawning/despawning.
- Geometry Instancing: Used where possible for identical particles.
- Shader Optimization: Custom shaders are optimized to minimize expensive operations in the fragment shader.
- Adaptive Performance: The controller monitors FPS and can dynamically adjust visual quality (e.g., particle counts, bloom intensity) if performance drops.