Give me a full-blown game that uses 3-JS to build Skyroads from the 1994 DOS game. I…
- User
Give me a full-blown game that uses 3-JS to build Skyroads from the 1994 DOS game. I want level one where I'm jumping in space.
Assistant
Skyroads Clone with Three.js
Here's a complete implementation of a Skyroads-inspired game using Three.js. This includes level 1 with jumping mechanics in a space environment.
HTML (index.html)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Skyroads Clone</title> <style> body { margin: 0; overflow: hidden; background-color: #000; font-family: Arial, sans-serif; } #game-container { position: relative; width: 100vw; height: 100vh; } #score-display { position: absolute; top: 20px; left: 20px; color: white; font-size: 24px; z-index: 100; } #start-screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); display: flex; flex-direction: column; justify-content: center; align-items: center; color: white; z-index: 200; } #start-button { margin-top: 20px; padding: 10px 20px; font-size: 18px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; } #game-over { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); display: none; flex-direction: column; justify-content: center; align-items: center; color: white; z-index: 200; } #restart-button { margin-top: 20px; padding: 10px 20px; font-size: 18px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; } </style> </head> <body> <div id="game-container"> <div id="score-display">Score: 0</div> <div id="start-screen"> <h1>Skyroads Clone</h1> <p>Use arrow keys to move and space to jump</p> <button id="start-button">Start Game</button> </div> <div id="game-over"> <h1>Game Over</h1> <p id="final-score">Score: 0</p> <button id="restart-button">Play Again</button> </div> </div> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/build/three.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/three@0.132.2/examples/js/controls/OrbitControls.js"></script> <script src="game.js"></script> </body> </html>JavaScript (game.js)
// Game constants const ROAD_WIDTH = 5; const ROAD_LENGTH = 10; const ROAD_HEIGHT = 0.5; const GAP_WIDTH = 3; const PLAYER_SIZE = 1; const GRAVITY = 0.05; const JUMP_FORCE = 0.3; const MOVE_SPEED = 0.2; const CAMERA_OFFSET = 10; // Game variables let scene, camera, renderer; let player, roads = []; let score = 0; let isGameOver = false; let isJumping = false; let velocityY = 0; let playerPosition = { x: 0, y: 1, z: 0 }; let keys = { ArrowLeft: false, ArrowRight: false, ArrowUp: false, ArrowDown: false, ' ': false }; // Initialize the game function init() { // Create scene scene = new THREE.Scene(); scene.background = new THREE.Color(0x000000); // Add stars addStars(); // Create camera camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.set(0, 5, CAMERA_OFFSET); camera.lookAt(0, 0, 0); // Create renderer renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); document.getElementById('game-container').appendChild(renderer.domElement); // Create player createPlayer(); // Create initial roads createInitialRoads(); // Add event listeners window.addEventListener('resize', onWindowResize); window.addEventListener('keydown', onKeyDown); window.addEventListener('keyup', onKeyUp); // Start button document.getElementById('start-button').addEventListener('click', startGame); document.getElementById('restart-button').addEventListener('click', restartGame); // Start animation loop animate(); } // Add stars to the background function addStars() { const starsGeometry = new THREE.BufferGeometry(); const starsMaterial = new THREE.PointsMaterial({ color: 0xFFFFFF, size: 0.1 }); const starsVertices = []; for (let i = 0; i < 1000; i++) { const x = (Math.random() - 0.5) * 2000; const y = (Math.random() - 0.5) * 2000; const z = (Math.random() - 0.5) * 2000; starsVertices.push(x, y, z); } starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3)); const stars = new THREE.Points(starsGeometry, starsMaterial); scene.add(stars); } // Create the player function createPlayer() { const geometry = new THREE.BoxGeometry(PLAYER_SIZE, PLAYER_SIZE, PLAYER_SIZE); const material = new THREE.MeshBasicMaterial({ color: 0x00FF00 }); player = new THREE.Mesh(geometry, material); player.position.set(playerPosition.x, playerPosition.y, playerPosition.z); scene.add(player); } // Create initial roads function createInitialRoads() { // Starting platform createRoad(0, 0, 0); // Generate first few roads for (let i = 1; i < 20; i++) { const lastRoad = roads[roads.length - 1]; const z = lastRoad.position.z - ROAD_LENGTH; const x = lastRoad.position.x + (Math.random() * 6 - 3); createRoad(x, 0, z); } } // Create a road segment function createRoad(x, y, z) { const geometry = new THREE.BoxGeometry(ROAD_WIDTH, ROAD_HEIGHT, ROAD_LENGTH); const material = new THREE.MeshBasicMaterial({ color: 0x3333FF }); const road = new THREE.Mesh(geometry, material); road.position.set(x, y, z); scene.add(road); roads.push(road); return road; } // Game loop function animate() { if (isGameOver) return; requestAnimationFrame(animate); // Move player movePlayer(); // Apply gravity applyGravity(); // Check collisions checkCollisions(); // Update camera updateCamera(); // Generate new roads generateRoads(); // Remove old roads removeOldRoads(); // Update score updateScore(); renderer.render(scene, camera); } // Move player based on key input function movePlayer() { if (keys.ArrowLeft) { playerPosition.x -= MOVE_SPEED; } if (keys.ArrowRight) { playerPosition.x += MOVE_SPEED; } if (keys.ArrowUp) { playerPosition.z -= MOVE_SPEED; } if (keys.ArrowDown) { playerPosition.z += MOVE_SPEED; } // Keep player within bounds playerPosition.x = Math.max(-ROAD_WIDTH/2, Math.min(ROAD_WIDTH/2, playerPosition.x)); player.position.set(playerPosition.x, playerPosition.y, playerPosition.z); } // Apply gravity to player function applyGravity() { if (isJumping) { playerPosition.y += velocityY; velocityY -= GRAVITY; // Check if player landed if (playerPosition.y <= 1) { playerPosition.y = 1; isJumping
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.