awacke1 commited on
Commit
09f6c2c
·
1 Parent(s): b697f89

Create main.js

Browse files
Files changed (1) hide show
  1. main.js +50 -0
main.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Set up the scene, camera, and renderer
2
+ const scene = new THREE.Scene();
3
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
4
+ const renderer = new THREE.WebGLRenderer();
5
+ renderer.setSize(window.innerWidth, window.innerHeight);
6
+ document.body.appendChild(renderer.domElement);
7
+
8
+ // Set up the Lunar Lander
9
+ const landerGeometry = new THREE.BoxGeometry();
10
+ const landerMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
11
+ const lander = new THREE.Mesh(landerGeometry, landerMaterial);
12
+ scene.add(lander);
13
+
14
+ // Set up the ground
15
+ const groundGeometry = new THREE.PlaneGeometry(5, 5);
16
+ const groundMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, side: THREE.DoubleSide });
17
+ const ground = new THREE.Mesh(groundGeometry, groundMaterial);
18
+ ground.rotation.x = Math.PI / 2;
19
+ scene.add(ground);
20
+
21
+ // Position camera and lander
22
+ camera.position.z = 5;
23
+ lander.position.y = 2;
24
+
25
+ // Handle user input
26
+ const onKeyDown = (event) => {
27
+ if (event.code === "Space") {
28
+ lander.position.y += 0.1;
29
+ }
30
+ };
31
+
32
+ document.addEventListener("keydown", onKeyDown);
33
+
34
+ // Game loop
35
+ const animate = () => {
36
+ requestAnimationFrame(animate);
37
+
38
+ // Update lander position
39
+ lander.position.y -= 0.01;
40
+
41
+ // Check for successful landing
42
+ if (lander.position.y <= 0.5 && Math.abs(lander.rotation.z) < 0.1) {
43
+ console.log("Landed successfully!");
44
+ // TODO: Transition to the Asteroids game
45
+ }
46
+
47
+ renderer.render(scene, camera);
48
+ };
49
+
50
+ animate();