broadfield-dev commited on
Commit
8350cbf
·
verified ·
1 Parent(s): 4ea9b13

Update static/tribalStage.js

Browse files
Files changed (1) hide show
  1. static/tribalStage.js +80 -8
static/tribalStage.js CHANGED
@@ -1,4 +1,3 @@
1
- // At the top of tribalStage.js
2
  let game;
3
 
4
  class TribalStage extends GameStage {
@@ -8,7 +7,7 @@ class TribalStage extends GameStage {
8
  this.huts = [];
9
  this.rivalTribes = [];
10
 
11
- // Load 3D models via URLs
12
  this.loadModels();
13
  }
14
 
@@ -30,7 +29,7 @@ class TribalStage extends GameStage {
30
 
31
  // Tribal Creature (Player)
32
  loader.load(
33
- "https://polyhaven.com/a/tribal_warrior", // Placeholder; download and host locally
34
  (gltf) => {
35
  this.creatureModel = gltf.scene;
36
  this.creatureModel.scale.set(0.5, 0.5, 0.5); // Scale down for game size
@@ -42,7 +41,7 @@ class TribalStage extends GameStage {
42
 
43
  // Hut
44
  loader.load(
45
- "https://polyhaven.com/a/hut", // Placeholder; download and host locally
46
  (gltf) => {
47
  this.hutModel = gltf.scene;
48
  this.hutModel.scale.set(0.5, 0.5, 0.5);
@@ -53,7 +52,7 @@ class TribalStage extends GameStage {
53
 
54
  // Rival Tribe
55
  loader.load(
56
- "https://sketchfab.com/3d-models/tribal-warrior-7b9f9f7e2b7b4a2a8f1c9d0e", // Placeholder; download and host locally
57
  (gltf) => {
58
  this.rivalModel = gltf.scene;
59
  this.rivalModel.scale.set(0.5, 0.5, 0.5);
@@ -69,8 +68,6 @@ class TribalStage extends GameStage {
69
  game = this; // Set the global game reference here
70
  }
71
 
72
- // ... (rest of the methods remain the same as before)
73
-
74
  spawnCreature(x, z) {
75
  const creature = this.creatureModel.clone();
76
  creature.position.set(x, 0, z);
@@ -80,7 +77,82 @@ class TribalStage extends GameStage {
80
  this.updateUI();
81
  }
82
 
83
- // ... (other methods like gatherFood, buildHut, etc., remain unchanged)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
86
  document.addEventListener("DOMContentLoaded", () => {
 
 
1
  let game;
2
 
3
  class TribalStage extends GameStage {
 
7
  this.huts = [];
8
  this.rivalTribes = [];
9
 
10
+ // Load 3D models via local paths (after downloading and hosting)
11
  this.loadModels();
12
  }
13
 
 
29
 
30
  // Tribal Creature (Player)
31
  loader.load(
32
+ "/static/assets/tribal_warrior.gltf",
33
  (gltf) => {
34
  this.creatureModel = gltf.scene;
35
  this.creatureModel.scale.set(0.5, 0.5, 0.5); // Scale down for game size
 
41
 
42
  // Hut
43
  loader.load(
44
+ "/static/assets/hut.gltf",
45
  (gltf) => {
46
  this.hutModel = gltf.scene;
47
  this.hutModel.scale.set(0.5, 0.5, 0.5);
 
52
 
53
  // Rival Tribe
54
  loader.load(
55
+ "/static/assets/rival_warrior.gltf",
56
  (gltf) => {
57
  this.rivalModel = gltf.scene;
58
  this.rivalModel.scale.set(0.5, 0.5, 0.5);
 
68
  game = this; // Set the global game reference here
69
  }
70
 
 
 
71
  spawnCreature(x, z) {
72
  const creature = this.creatureModel.clone();
73
  creature.position.set(x, 0, z);
 
77
  this.updateUI();
78
  }
79
 
80
+ spawnRivalTribe(x, z) {
81
+ const tribe = this.rivalModel.clone();
82
+ tribe.position.set(x, 0, z);
83
+ this.scene.add(tribe);
84
+ this.rivalTribes.push({ model: tribe, members: 3, hostile: true });
85
+ }
86
+
87
+ gatherFood() {
88
+ this.resources.food += 5 * this.creatures.length;
89
+ this.updateUI();
90
+ }
91
+
92
+ buildHut() {
93
+ if (this.resources.food >= 20 && this.huts.length < 5) {
94
+ this.resources.food -= 20;
95
+ const hut = this.hutModel.clone();
96
+ hut.position.set(-5 + this.huts.length, 0, 0);
97
+ this.scene.add(hut);
98
+ this.huts.push(hut);
99
+ this.maxPopulation += 2;
100
+ this.spawnCreature(0, 0);
101
+ }
102
+ this.updateUI();
103
+ }
104
+
105
+ attackTribe() {
106
+ if (this.rivalTribes.length > 0 && this.creatures.length > 1) {
107
+ this.rivalTribes[0].members -= 1;
108
+ if (this.rivalTribes[0].members <= 0) {
109
+ this.scene.remove(this.rivalTribes[0].model);
110
+ this.rivalTribes.shift();
111
+ this.relations = "Victorious";
112
+ } else {
113
+ this.relations = "Hostile";
114
+ }
115
+ this.updateUI();
116
+ }
117
+ }
118
+
119
+ socializeTribe() {
120
+ if (this.rivalTribes.length > 0 && this.resources.food >= 10) {
121
+ this.resources.food -= 10;
122
+ this.rivalTribes[0].hostile = false;
123
+ this.relations = "Friendly";
124
+ this.updateUI();
125
+ }
126
+ }
127
+
128
+ applyCreatureChanges() {
129
+ const color = document.getElementById("creatureColor").value;
130
+ const scale = parseFloat(document.getElementById("creatureSize").value);
131
+ this.creatures.forEach(c => {
132
+ c.model.traverse((child) => {
133
+ if (child.isMesh) {
134
+ child.material.color.set(color);
135
+ c.model.scale.set(scale, scale, scale);
136
+ }
137
+ });
138
+ });
139
+ toggleEditor(); // Hide editor after applying
140
+ }
141
+
142
+ update() {
143
+ this.creatures.forEach(creature => {
144
+ creature.model.position.x += (Math.random() - 0.5) * creature.speed;
145
+ creature.model.position.z += (Math.random() - 0.5) * creature.speed;
146
+ creature.model.position.x = Math.max(-50, Math.min(50, creature.model.position.x));
147
+ creature.model.position.z = Math.max(-50, Math.min(50, creature.model.position.z));
148
+ });
149
+ }
150
+
151
+ animate() {
152
+ requestAnimationFrame(() => this.animate());
153
+ this.update();
154
+ this.renderer.render(this.scene, this.camera);
155
+ }
156
  }
157
 
158
  document.addEventListener("DOMContentLoaded", () => {