This is going to be a mind-bending experience! We'll create a website that looks like a YouTube page, but instead of a typical video, you'll see a playable 3D first-person game embedded right where the video player would be.
The game is a minimalist, neon-infused maze that simulates navigating a digital void. You'll use WASD keys and your mouse to move, aiming to reach a portal. The entire site is styled to resemble a YouTube interface, with a header, sidebar for "related content," and video details.
The Concept: "YouTube VR: The Glitch Maze"
You're browsing YouTube, looking for some cool sci-fi content. You click on a video titled "🚀 Interstellar Voyage: Navigating the Neon Void," but instead of a video, you're dropped into a full-screen 3D game controlled by your mouse and keyboard.
✅ Features:
YouTube Interface Mimicry: Dark theme, header, sidebar with "related" links.
WebGL Game: A first-person perspective game using Three.js rendered directly into a canvas.
Game Controls: WASD for movement, mouse to look around.
Objective: Navigate a neon maze to reach a glowing portal.
Start Screen: An overlay with a "play" button to initiate the game.
Responsive Design: Adapts to different screen sizes.
Crazy Integration: The "video" is the game.
💻 Code: Copy & Paste into index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube VR | 3D Space Maze</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@700&family=Press+Start+2P&family=VT323&display=swap" rel="stylesheet">
<!-- Three.js Library -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.1/three.min.js"></script>
<!-- Pointer Lock Controls for First-Person Camera -->
<script src="https://cdn.jsdelivr.net/npm/three@0.160.1/examples/js/controls/PointerLockControls.js"></script>
<style>
/* --- Global Setup & YouTube Theme --- */
:root {
--yt-dark-bg: #181818;
--yt-darker-bg: #282828;
--yt-grey-text: #AAAAAA;
--yt-red: #FF0000;
--yt-cyan: #00FFFF;
--yt-pink: #FF00FF;
--yt-neon-green: #00ff99;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Press Start 2P', cursive;
background-color: var(--yt-dark-bg);
color: var(--yt-grey-text);
overflow: hidden; /* Game canvas will manage its own view */
display: flex;
justify-content: center;
align-items: flex-start;
padding-top: 60px; /* Simulate YouTube header height */
min-height: 100vh;
}
/* YouTube Header Simulation */
.yt-header {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 60px;
background-color: var(--yt-darker-bg);
color: white;
display: flex;
align-items: center;
padding: 0 20px;
z-index: 100;
font-family: 'VT323', monospace; /* Pixelated font for tech feel */
font-size: 1.8rem;
box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
.yt-header .logo { color: var(--yt-red); font-weight: bold; margin-right: 15px; }
.yt-header input[type="text"] {
padding: 8px 12px;
border: 1px solid #555;
background: #000; /* Dark input background */
color: #eee;
font-size: 1rem;
flex-grow: 1;
margin: 0 10px;
}
/* Main Content Layout */
.main-content {
display: flex;
width: 90%;
max-width: 1200px; /* Max width for the content area */
margin-top: 20px;
}
.video-section {
flex-grow: 1; /* Takes up available space */
margin-right: 20px;
}
.video-player-wrapper {
position: relative;
width: 100%;
background-color: #000;
aspect-ratio: 16 / 9; /* Standard video aspect ratio */
display: flex;
justify-content: center;
align-items: center;
overflow: hidden; /* Crucial for canvas rendering */
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0,0,0,0.7);
border: 5px solid var(--yt-red); /* YT-like red border */
}
.game-canvas {
display: block; /* Remove extra space below canvas */
outline: none; /* Remove focus outline on canvas */
}
/* Start Button Overlay - Hidden when game is active */
.start-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8); /* Semi-transparent black */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 10;
transition: opacity 0.5s ease;
cursor: pointer; /* Indicate it's clickable */
color: var(--yt-cyan);
}
.start-overlay.hidden {
opacity: 0;
pointer-events: none; /* Disable clicks when hidden */
}
.start-overlay h2 {
font-family: 'Orbitron', sans-serif;
font-size: 2.5rem;
color: var(--yt-cyan);
text-shadow: 0 0 10px var(--yt-cyan), 0 0 20px var(--yt-pink);
animation: pulseGlow 2s infinite;
text-align: center;
}
.start-overlay p {
font-size: 1rem;
color: var(--yt-grey-text);
margin-bottom: 30px;
}
.start-overlay button {
padding: 15px 30px;
background: var(--yt-red);
color: #fff;
border: 3px solid #fff;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.3s;
font-family: 'Press Start 2P', cursive;
box-shadow: 0 0 15px var(--yt-red);
}
.start-overlay button:hover {
background: #fff;
color: var(--yt-red);
box-shadow: 0 0 25px var(--yt-red);
}
/* Animation for title glow */
@keyframes pulseGlow {
0% { text-shadow: 0 0 10px var(--yt-cyan), 0 0 20px var(--yt-pink); }
50% { text-shadow: 0 0 15px var(--yt-cyan), 0 0 25px var(--yt-pink); }
100% { text-shadow: 0 0 10px var(--yt-cyan), 0 0 20px var(--yt-pink); }
}
/* Sidebar Styling */
.sidebar {
width: 300px; /* Fixed width for sidebar */
background-color: var(--yt-darker-bg);
padding: 15px;
border-radius: 5px;
box-shadow: 0 5px 15px rgba(0,0,0,0.7);
height: fit-content; /* Adjust height based on content */
}
.sidebar h3 {
color: #fff;
font-size: 1.2rem;
margin-bottom: 15px;
border-bottom: 1px solid #555;
padding-bottom: 5px;
}
.sidebar a {
display: flex; /* Use flex for image and text alignment */
align-items: center;
color: var(--yt-grey-text);
text-decoration: none;
margin-bottom: 10px;
font-size: 0.9rem;
transition: color 0.2s;
padding: 5px;
border-radius: 3px;
}
.sidebar a:hover {
color: var(--yt-cyan);
background-color: var(--yt-darker-bg); /* Subtle hover background */
}
.sidebar a img {
width: 40px;
height: 40px;
margin-right: 10px;
border-radius: 3px;
flex-shrink: 0; /* Prevent image from shrinking */
}
</style>
</head>
<body>
<!-- Simulated YouTube Header -->
<div class="yt-header">
<div class="logo"> YT-CTRL </div>
<input type="text" placeholder="Search for space adventures...">
<span>👤 User_0x0F</span>
</div>
<div class="main-content">
<!-- Video Section (which hosts our game) -->
<section class="video-section">
<div class="video-player-wrapper" id="playerWrapper">
<!-- The Canvas for Three.js Game -->
<canvas class="game-canvas" id="gameCanvas"></canvas>
<!-- Overlay for Starting the Game -->
<div class="start-overlay" id="startOverlay">
<h2>WARNING: UNSTABLE REALITY</h2>
<p>Initiate 3D Navigation Protocol?</p>
<button id="startButton">INITIATE</button>
</div>
</div>
<!-- Simulated Video Title and Description -->
<div style="padding-top: 15px;">
<h3 style="font-size: 1.8rem; color: #fff;">🚀 Interstellar Voyage: Navigating the Neon Void</h3>
<p style="font-size: 0.9rem; color: #AAA;">Channel: Glitch Gaming Hub | 1.5M Views | 2 Weeks ago</p>
<div style="margin-top: 15px; border-top: 1px solid #555; padding-top: 10px;">
<p>Description: Dive into a mind-bending first-person journey through a dynamically generated neon void. Can you reach the portal and stabilize reality?</p>
</div>
</div>
</section>
<!-- Sidebar with "Related" Content -->
<aside class="sidebar">
<h3>🌌 Related Missions</h3>
<a href="#">
<img src="https://i.ytimg.com/vi/dQw4w9WgXcQ/hq720.jpg?sqp=-oaymwEbCK4FEHJDfyqVKgbVc3A2N5FzJzK00g0Dg13JvH4k&rs=AOn4CLCC190gqf9eEaN5xV9wD7o1z5H_8A" alt="Thumbnail">
<span>Retro Space Shooter Tutorial</span>
</a>
<a href="#">
<img src="https://i.ytimg.com/vi/6E2CW55I33M/hq720.jpg?sqp=-oaymwEbCK4FEHJDfyqVKgbVc3A2N5FzJzK00g0Dg13JvH4k&rs=AOn4CLC3u0JgQ9N_e2O4t-J3sK2y9fI0nA" alt="Thumbnail">
<span>Building a Sci-Fi City in Blender</span>
</a>
<a href="#">
<img src="https://i.ytimg.com/vi/3_mS2M03m_E/hq720.jpg?sqp=-oaymwEbCK4FEHJDfyqVKgbVc3A2N5FzJzK00g0Dg13JvH4k&rs=AOn4CLBPn8J1s0N9M9m6Sj5LhO8Xv0w8bQ" alt="Thumbnail">
<span>3D Particle Effects with Three.js</span>
</a>
<a href="#">
<img src="https://i.ytimg.com/vi/fM55N0_51_U/hq720.jpg?sqp=-oaymwEbCK4FEHJDfyqVKgbVc3A2N5FzJzK00g0Dg13JvH4k&rs=AOn4CLChz4M3mB-s5fB2-rT4e2yR4x6L5Q" alt="Thumbnail">
<span>The Future of VR Interfaces</span>
</a>
</aside>
</div>
<!-- JavaScript for Three.js Game and Interactions -->
<script>
// --- DOM Elements ---
const startOverlay = document.getElementById('startOverlay');
const startButton = document.getElementById('startButton');
const gameCanvas = document.getElementById('gameCanvas');
const playerWrapper = document.getElementById('playerWrapper');
// --- Three.js Variables ---
let scene, camera, renderer, controls;
let portalMesh; // To access the portal for rotation and collision
let gameStarted = false;
let cubes = []; // To store floating cubes for rotation
// --- Game Constants ---
const GAME_WIDTH = 16; // Aspect ratio width for canvas
const GAME_HEIGHT = 9; // Aspect ratio height for canvas
const GRAVITY = 9.8; // Although not used for movement here, good practice
const MOVEMENT_SPEED = 8.0; // Units per second
const LOOK_SPEED = 0.002; // Mouse sensitivity
// --- Initialization Function ---
function init() {
// Scene Setup
scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a0117); // Deep space void
// Camera Setup
// Aspect ratio is determined by the wrapper, not window. It's 16:9
camera = new THREE.PerspectiveCamera(75, GAME_WIDTH / GAME_HEIGHT, 0.1, 1000);
// PointerLockControls for First-Person Movement
// We attach it to the canvas to capture mouse input within the game area
controls = new THREE.PointerLockControls(camera, gameCanvas);
scene.add(controls.getObject()); // Add the camera object controlled by PointerLockControls to the scene
// Set initial camera position relative to controls object
controls.getObject().position.y = 5; // Start player slightly above the ground
// Renderer Setup
renderer = new THREE.WebGLRenderer({ canvas: gameCanvas, antialias: true });
// Adjust canvas size based on wrapper's actual size and device pixel ratio
handleWindowResize(); // Call once on init
window.addEventListener('resize', handleWindowResize);
// Lighting
const ambientLight = new THREE.AmbientLight(0xffffff, 0.5); // Soft white light
scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0x00ffff, 0.8); // Cyan light for neon effect
directionalLight.position.set(5, 5, 5);
scene.add(directionalLight);
// --- Game Elements ---
// Floor/Ground (Invisible, just for collision detection if needed, or a visual plane)
const groundGeometry = new THREE.PlaneGeometry(200, 200, 10, 10);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x00ff99, // Neon green
side: THREE.DoubleSide,
transparent: true,
opacity: 0.1,
wireframe: true,
wireframeLinewidth: 1
});
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = -Math.PI / 2; // Rotate to be horizontal
ground.position.y = -1; // Slightly below the player's start
scene.add(ground);
// Floating Platforms
const platformMaterial = new THREE.MeshStandardMaterial({ color: 0xffff00, emissive: 0xffff00, emissiveIntensity: 1 });
const platformGeometry = new THREE.BoxGeometry(5, 0.5, 5);
const platform1 = new THREE.Mesh(platformGeometry, platformMaterial);
platform1.position.set(0, 2.25, -10);
scene.add(platform1);
const platform2 = new THREE.Mesh(platformGeometry, platformMaterial);
platform2.position.set(10, 3.75, -20);
scene.add(platform2);
const platform3 = new THREE.Mesh(platformGeometry, platformMaterial);
platform3.position.set(-15, 5.25, -30);
scene.add(platform3);
// Portal (The Goal)
const portalGeometry = new THREE.TorusGeometry(2, 1, 32, 64); // Torus shape
const portalMaterial = new THREE.MeshStandardMaterial({
color: 0x00ffff, // Cyan
emissive: 0x00ffff,
emissiveIntensity: 1.5,
transparent: true,
opacity: 0.8
});
portalMesh = new THREE.Mesh(portalGeometry, portalMaterial);
portalMesh.position.set(0, 6.75, -40); // Position it in the distance
portalMesh.rotation.x = Math.PI / 2; // Rotate it to face forward
scene.add(portalMesh);
// Small Floating Cubes for Visuals
const cubeMaterial = new THREE.MeshStandardMaterial({ color: 0xff00ff, emissive: 0xff00ff, emissiveIntensity: 0.5 });
for (let i = 0; i < 30; i++) {
const cube = new THREE.Mesh(new THREE.BoxGeometry(0.5, 0.5, 0.5), cubeMaterial);
cube.position.x = (Math.random() - 0.5) * 100;
cube.position.y = Math.random() * 20 + 2; // Keep them above the ground
cube.position.z = (Math.random() - 0.5) * 60 - 20; // Spread them out
scene.add(cube);
cubes.push(cube); // Store for animation
}
// --- Event Listeners for Game Control ---
document.addEventListener('pointerlockchange', onPointerlockChange, false);
// Add a listener to start the game when the overlay is clicked
playerWrapper.addEventListener('click', () => {
if (!gameStarted) {
controls.lock(); // Request pointer lock
}
});
startButton.addEventListener('click', (event) => {
event.stopPropagation(); // Prevent click from propagating to playerWrapper
controls.lock(); // Request pointer lock
});
// Start the animation loop
animate();
}
// --- Animation Loop ---
function animate() {
requestAnimationFrame(animate);
if (gameStarted) {
// Update game elements
portalMesh.rotation.y += 0.03; // Rotate the portal
// Rotate floating cubes
cubes.forEach(cube => {
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
});
// Check collision with the portal
const playerPos = controls.getObject().position;
const portalPos = portalMesh.position;
// Calculate distance from player's center to portal's center
const distanceToPortal = playerPos.distanceTo(portalPos);
if (distanceToPortal < 3) { // Player is close enough to the portal
alert("You reached the core! Reality stabilized.");
// Reset game state to show overlay again
gameStarted = false;
controls.unlock(); // Unlock the mouse
startOverlay.classList.remove('hidden'); // Show the overlay again
// Reset player position for next game
controls.getObject().position.set(0, 5, 5);
}
}
// Render the scene
renderer.render(scene, camera);
}
// --- Utility Functions ---
// Handle resizing the canvas and renderer
function handleWindowResize() {
const wrapperRect = playerWrapper.getBoundingClientRect();
// Set canvas drawing buffer size, scaled by device pixel ratio
const canvasWidth = wrapperRect.width * window.devicePixelRatio;
const canvasHeight = wrapperRect.height * window.devicePixelRatio;
// Set the canvas HTML element dimensions to visually match the wrapper
gameCanvas.style.width = `${wrapperRect.width}px`;
gameCanvas.style.height = `${wrapperRect.height}px`;
// Set the renderer's drawing buffer size. 'false' means CSS size isn't adjusted.
renderer.setSize(canvasWidth, canvasHeight, false);
// Update camera aspect ratio to match the wrapper's visual aspect ratio
camera.aspect = wrapperRect.width / wrapperRect.height;
camera.updateProjectionMatrix();
}
// Handler for pointer lock state changes
function onPointerlockChange() {
if (document.pointerLockElement === gameCanvas) { // If pointer is locked to our canvas
gameStarted = true;
startOverlay.classList.add('hidden'); // Hide the start overlay
} else { // If pointer lock is lost (e.g., ESC pressed)
gameStarted = false;
startOverlay.classList.remove('hidden'); // Show the start overlay again
}
}
// --- Start the game process ---
// Initialize the game when the page loads, but game logic only runs when started
init();
</script>
</body>
</html>
🚀 How it Works & Why It's Crazy:
YouTube Layout: The HTML and CSS are crafted to mimic the familiar look and feel of a YouTube video page. You have a header with a logo, search bar, and user profile, along with a sidebar showing "related" content.
The "Video" is a Game: The video-player-wrapper contains a <canvas> element. This canvas is where the entire 3D game world is rendered using Three.js.
First-Person Control: The PointerLockControls from Three.js are used to give you first-person camera movement. When you click the "INITIATE" button (or the canvas area), your mouse cursor is locked to the canvas, allowing you to look around and move with WASD keys.
Interactive Game World: You're dropped into a void with neon-colored platforms, floating cubes, and a pulsating portal. Your goal is to navigate the maze and reach the portal.
Surprise Element: The surprise is that what appears to be a video is actually an interactive 3D game. The context of it being on a "YouTube" page makes the transition into a game world feel like a digital breach or a hidden feature.
💡 Tips for Customization:
More Game Content: Add more complex mazes, collectibles, enemies, or puzzles.
Visual Effects: Integrate particle systems for ambient effects, or post-processing shaders for bloom, depth of field, or more intense glitch effects.
Sound: Add background ambient sci-fi music or sound effects for movement, picking up items, or reaching the portal using the Web Audio API.
Dynamic Content: Make the "related missions" in the sidebar change based on the player's progress in the game.
Easter Eggs: Hide secret areas or codes within the 3D environment!
This setup blurs the lines between consuming content and interacting with it, offering a truly unique and surprising web experience!