Spaces:
Sleeping
Sleeping
Update static/game.js
Browse files- static/game.js +36 -9
static/game.js
CHANGED
@@ -1,11 +1,40 @@
|
|
1 |
class GameStage {
|
2 |
-
constructor(
|
3 |
-
this.
|
4 |
-
this.
|
|
|
|
|
|
|
|
|
5 |
this.resources = { food: 0 };
|
6 |
this.population = 1;
|
7 |
this.maxPopulation = 5;
|
8 |
-
this.relations = "Neutral";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
}
|
10 |
|
11 |
updateUI() {
|
@@ -14,11 +43,9 @@ class GameStage {
|
|
14 |
document.getElementById("relations").textContent = `Relations: ${this.relations}`;
|
15 |
}
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
img.src = url;
|
21 |
-
return img;
|
22 |
}
|
23 |
}
|
24 |
|
|
|
1 |
class GameStage {
|
2 |
+
constructor() {
|
3 |
+
this.scene = new THREE.Scene();
|
4 |
+
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
|
5 |
+
this.renderer = new THREE.WebGLRenderer({ antialias: true });
|
6 |
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
7 |
+
document.body.appendChild(this.renderer.domElement);
|
8 |
+
|
9 |
this.resources = { food: 0 };
|
10 |
this.population = 1;
|
11 |
this.maxPopulation = 5;
|
12 |
+
this.relations = "Neutral";
|
13 |
+
|
14 |
+
this.camera.position.set(0, 10, 20); // Position above the scene for a top-down view
|
15 |
+
this.camera.lookAt(0, 0, 0);
|
16 |
+
|
17 |
+
// Add ground
|
18 |
+
const groundGeometry = new THREE.PlaneGeometry(100, 100);
|
19 |
+
const groundMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); // Placeholder green for grass
|
20 |
+
this.ground = new THREE.Mesh(groundGeometry, groundMaterial);
|
21 |
+
this.ground.rotation.x = -Math.PI / 2; // Rotate to lie flat
|
22 |
+
this.scene.add(this.ground);
|
23 |
+
|
24 |
+
this.objects = [];
|
25 |
+
this.updateUI = this.updateUI.bind(this);
|
26 |
+
|
27 |
+
window.addEventListener('resize', () => {
|
28 |
+
this.camera.aspect = window.innerWidth / window.innerHeight;
|
29 |
+
this.camera.updateProjectionMatrix();
|
30 |
+
this.renderer.setSize(window.innerWidth, window.innerHeight);
|
31 |
+
});
|
32 |
+
}
|
33 |
+
|
34 |
+
loadAsset(url, onLoad, onError) {
|
35 |
+
const loader = new THREE.TextureLoader();
|
36 |
+
loader.crossOrigin = "anonymous"; // For CORS
|
37 |
+
loader.load(url, onLoad, undefined, onError);
|
38 |
}
|
39 |
|
40 |
updateUI() {
|
|
|
43 |
document.getElementById("relations").textContent = `Relations: ${this.relations}`;
|
44 |
}
|
45 |
|
46 |
+
animate() {
|
47 |
+
requestAnimationFrame(() => this.animate());
|
48 |
+
this.renderer.render(this.scene, this.camera);
|
|
|
|
|
49 |
}
|
50 |
}
|
51 |
|