broadfield-dev commited on
Commit
3790364
·
verified ·
1 Parent(s): 16d1c4f

Update static/tribalStage.js

Browse files
Files changed (1) hide show
  1. static/tribalStage.js +10 -74
static/tribalStage.js CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  class TribalStage extends GameStage {
2
  constructor() {
3
  super();
@@ -27,7 +30,7 @@ class TribalStage extends GameStage {
27
 
28
  // Tribal Creature (Player)
29
  loader.load(
30
- "https://polyhaven.com/a/tribal_warrior", // Simplified URL; download GLTF from Poly Haven
31
  (gltf) => {
32
  this.creatureModel = gltf.scene;
33
  this.creatureModel.scale.set(0.5, 0.5, 0.5); // Scale down for game size
@@ -39,7 +42,7 @@ class TribalStage extends GameStage {
39
 
40
  // Hut
41
  loader.load(
42
- "https://polyhaven.com/a/hut", // Download GLTF from Poly Haven
43
  (gltf) => {
44
  this.hutModel = gltf.scene;
45
  this.hutModel.scale.set(0.5, 0.5, 0.5);
@@ -50,7 +53,7 @@ class TribalStage extends GameStage {
50
 
51
  // Rival Tribe
52
  loader.load(
53
- "https://sketchfab.com/3d-models/tribal-warrior-7b9f9f7e2b7b4a2a8f1c9d0e", // Download GLTF, free version
54
  (gltf) => {
55
  this.rivalModel = gltf.scene;
56
  this.rivalModel.scale.set(0.5, 0.5, 0.5);
@@ -63,8 +66,11 @@ class TribalStage extends GameStage {
63
 
64
  init() {
65
  this.animate();
 
66
  }
67
 
 
 
68
  spawnCreature(x, z) {
69
  const creature = this.creatureModel.clone();
70
  creature.position.set(x, 0, z);
@@ -74,79 +80,9 @@ class TribalStage extends GameStage {
74
  this.updateUI();
75
  }
76
 
77
- spawnRivalTribe(x, z) {
78
- const tribe = this.rivalModel.clone();
79
- tribe.position.set(x, 0, z);
80
- this.scene.add(tribe);
81
- this.rivalTribes.push({ model: tribe, members: 3, hostile: true });
82
- }
83
-
84
- gatherFood() {
85
- this.resources.food += 5 * this.creatures.length;
86
- this.updateUI();
87
- }
88
-
89
- buildHut() {
90
- if (this.resources.food >= 20 && this.huts.length < 5) {
91
- this.resources.food -= 20;
92
- const hut = this.hutModel.clone();
93
- hut.position.set(-5 + this.huts.length, 0, 0);
94
- this.scene.add(hut);
95
- this.huts.push(hut);
96
- this.maxPopulation += 2;
97
- this.spawnCreature(0, 0);
98
- }
99
- this.updateUI();
100
- }
101
-
102
- attackTribe() {
103
- if (this.rivalTribes.length > 0 && this.creatures.length > 1) {
104
- this.rivalTribes[0].members -= 1;
105
- if (this.rivalTribes[0].members <= 0) {
106
- this.scene.remove(this.rivalTribes[0].model);
107
- this.rivalTribes.shift();
108
- this.relations = "Victorious";
109
- } else {
110
- this.relations = "Hostile";
111
- }
112
- this.updateUI();
113
- }
114
- }
115
-
116
- socializeTribe() {
117
- if (this.rivalTribes.length > 0 && this.resources.food >= 10) {
118
- this.resources.food -= 10;
119
- this.rivalTribes[0].hostile = false;
120
- this.relations = "Friendly";
121
- this.updateUI();
122
- }
123
- }
124
-
125
- applyCreatureChanges() {
126
- const color = document.getElementById("creatureColor").value;
127
- const scale = parseFloat(document.getElementById("creatureSize").value);
128
- this.creatures.forEach(c => {
129
- c.model.traverse((child) => {
130
- if (child.isMesh) {
131
- child.material.color.set(color);
132
- c.model.scale.set(scale, scale, scale);
133
- }
134
- });
135
- });
136
- toggleEditor(); // Hide editor after applying
137
- }
138
-
139
- update() {
140
- this.creatures.forEach(creature => {
141
- creature.model.position.x += (Math.random() - 0.5) * creature.speed;
142
- creature.model.position.z += (Math.random() - 0.5) * creature.speed;
143
- creature.model.position.x = Math.max(-50, Math.min(50, creature.model.position.x));
144
- creature.model.position.z = Math.max(-50, Math.min(50, creature.model.position.z));
145
- });
146
- }
147
  }
148
 
149
- let game;
150
  document.addEventListener("DOMContentLoaded", () => {
151
  game = new TribalStage();
152
  game.init();
 
1
+ // At the top of tribalStage.js
2
+ let game;
3
+
4
  class TribalStage extends GameStage {
5
  constructor() {
6
  super();
 
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
 
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
 
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);
 
66
 
67
  init() {
68
  this.animate();
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
  this.updateUI();
81
  }
82
 
83
+ // ... (other methods like gatherFood, buildHut, etc., remain unchanged)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }
85
 
 
86
  document.addEventListener("DOMContentLoaded", () => {
87
  game = new TribalStage();
88
  game.init();