File size: 1,468 Bytes
09f6c2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Set up the scene, camera, and renderer
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// Set up the Lunar Lander
const landerGeometry = new THREE.BoxGeometry();
const landerMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
const lander = new THREE.Mesh(landerGeometry, landerMaterial);
scene.add(lander);

// Set up the ground
const groundGeometry = new THREE.PlaneGeometry(5, 5);
const groundMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide });
const ground = new THREE.Mesh(groundGeometry, groundMaterial);
ground.rotation.x = Math.PI / 2;
scene.add(ground);

// Position camera and lander
camera.position.z = 5;
lander.position.y = 2;

// Handle user input
const onKeyDown = (event) => {
  if (event.code === "Space") {
    lander.position.y += 0.1;
  }
};

document.addEventListener("keydown", onKeyDown);

// Game loop
const animate = () => {
  requestAnimationFrame(animate);

  // Update lander position
  lander.position.y -= 0.01;

  // Check for successful landing
  if (lander.position.y <= 0.5 && Math.abs(lander.rotation.z) < 0.1) {
    console.log("Landed successfully!");
    // TODO: Transition to the Asteroids game
  }

  renderer.render(scene, camera);
};

animate();