broadfield-dev commited on
Commit
fef3608
·
verified ·
1 Parent(s): b0d2ee8

Update static/tribalStage.js

Browse files
Files changed (1) hide show
  1. static/tribalStage.js +19 -25
static/tribalStage.js CHANGED
@@ -4,24 +4,21 @@ class TribalStage extends GameStage {
4
  this.creatures = [];
5
  this.huts = [];
6
  this.rivalTribes = [];
7
- this.patterns = {}; // Store loaded patterns
8
  this.loadPatterns();
9
  }
10
 
11
  loadPatterns() {
12
- // Load grass texture for background
13
- this.patterns.grass = this.loadPattern("https://cdn.pixabay.com/photo/2013/07/12/18/40/grass-150056_1280.png", 32, 32);
14
- // Load tribal pattern for creatures
15
- this.patterns.creature = this.loadPattern("https://cdn.pixabay.com/photo/2023/05/15/10/32/ai-generated-7994367_1280.png", 32, 32);
16
- // Load wood texture for huts
17
- this.patterns.hut = this.loadPattern("https://cdn.pixabay.com/photo/2014/03/25/16/53/wood-295552_1280.png", 48, 48);
18
- // Load apple for food
19
- this.patterns.food = this.loadPattern("https://cdn.pixabay.com/photo/2013/07/12/07/25/apple-151229_1280.png", 16, 16);
20
  }
21
 
22
- loadPattern(url, width, height) {
23
  const img = new Image();
24
- img.crossOrigin = "anonymous"; // Try to handle CORS, but we’ll fallback if it fails
25
  img.src = url;
26
  let pattern = null;
27
  img.onload = () => {
@@ -31,7 +28,7 @@ class TribalStage extends GameStage {
31
  console.error("Failed to load pattern:", url);
32
  pattern = this.ctx.createPattern(new Uint8ClampedArray([255, 255, 255, 255]), "repeat"); // Fallback to white
33
  };
34
- return () => pattern || this.ctx.createPattern(new Uint8ClampedArray([255, 255, 255, 255]), "repeat"); // Fallback
35
  }
36
 
37
  init() {
@@ -109,39 +106,36 @@ class TribalStage extends GameStage {
109
  render() {
110
  this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
111
 
112
- // Draw grass background (using pattern)
113
- this.ctx.fillStyle = this.patterns.grass();
114
  this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
115
 
116
- // Draw huts (wood-patterned rectangles)
117
  this.huts.forEach(hut => {
118
  this.ctx.fillStyle = this.patterns.hut();
119
  this.ctx.fillRect(hut.x, hut.y, 48, 48);
120
  });
121
 
122
- // Draw rival tribes (red or green circles with tribal pattern)
123
  this.rivalTribes.forEach(tribe => {
124
- this.ctx.fillStyle = tribe.hostile ? "red" : "green";
125
  this.ctx.beginPath();
126
  this.ctx.arc(tribe.x + 16, tribe.y + 16, 16, 0, Math.PI * 2);
127
  this.ctx.fill();
128
- this.ctx.fillStyle = this.patterns.creature();
129
- this.ctx.fill();
130
  this.ctx.fillText(`Members: ${tribe.members}`, tribe.x, tribe.y - 10);
131
  });
132
 
133
- // Draw creatures (circles with tribal pattern and custom color overlay)
134
  this.creatures.forEach(creature => {
135
- this.ctx.fillStyle = creature.color || "#ff0000";
136
  this.ctx.beginPath();
137
  this.ctx.arc(creature.x + creature.size / 2, creature.y + creature.size / 2, creature.size / 2, 0, Math.PI * 2);
138
  this.ctx.fill();
139
- this.ctx.fillStyle = this.patterns.creature();
140
- this.ctx.fill();
141
  });
142
 
143
- // Optionally draw food (small apple icon)
144
- if (this.resources.food > 0 && this.patterns.food()) {
145
  this.ctx.fillStyle = this.patterns.food();
146
  this.ctx.fillRect(50, 50, 16, 16); // Example position for food
147
  }
 
4
  this.creatures = [];
5
  this.huts = [];
6
  this.rivalTribes = [];
7
+ this.patterns = {};
8
  this.loadPatterns();
9
  }
10
 
11
  loadPatterns() {
12
+ this.patterns.background = this.loadPattern("https://www.transparenttextures.com/patterns/subtle-white-feathers.png");
13
+ this.patterns.creature = this.loadPattern("https://www.transparenttextures.com/patterns/dark-wood.png");
14
+ this.patterns.hut = this.loadPattern("https://www.transparenttextures.com/patterns/wood-pattern.png");
15
+ this.patterns.rival = this.loadPattern("https://www.transparenttextures.com/patterns/dark-mosaic.png");
16
+ this.patterns.food = this.loadPattern("https://www.transparenttextures.com/patterns/red-paper.png");
 
 
 
17
  }
18
 
19
+ loadPattern(url) {
20
  const img = new Image();
21
+ img.crossOrigin = "anonymous"; // Attempt to handle CORS
22
  img.src = url;
23
  let pattern = null;
24
  img.onload = () => {
 
28
  console.error("Failed to load pattern:", url);
29
  pattern = this.ctx.createPattern(new Uint8ClampedArray([255, 255, 255, 255]), "repeat"); // Fallback to white
30
  };
31
+ return () => pattern || this.ctx.createPattern(new Uint8ClampedArray([255, 255, 255, 255]), "repeat"); // Return pattern or fallback
32
  }
33
 
34
  init() {
 
106
  render() {
107
  this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
108
 
109
+ // Draw background with subtle white feathers pattern
110
+ this.ctx.fillStyle = this.patterns.background();
111
  this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
112
 
113
+ // Draw huts with wood pattern
114
  this.huts.forEach(hut => {
115
  this.ctx.fillStyle = this.patterns.hut();
116
  this.ctx.fillRect(hut.x, hut.y, 48, 48);
117
  });
118
 
119
+ // Draw rival tribes with dark mosaic pattern
120
  this.rivalTribes.forEach(tribe => {
121
+ this.ctx.fillStyle = this.patterns.rival();
122
  this.ctx.beginPath();
123
  this.ctx.arc(tribe.x + 16, tribe.y + 16, 16, 0, Math.PI * 2);
124
  this.ctx.fill();
125
+ this.ctx.fillStyle = tribe.hostile ? "red" : "green";
 
126
  this.ctx.fillText(`Members: ${tribe.members}`, tribe.x, tribe.y - 10);
127
  });
128
 
129
+ // Draw creatures with dark wood pattern
130
  this.creatures.forEach(creature => {
131
+ this.ctx.fillStyle = this.patterns.creature();
132
  this.ctx.beginPath();
133
  this.ctx.arc(creature.x + creature.size / 2, creature.y + creature.size / 2, creature.size / 2, 0, Math.PI * 2);
134
  this.ctx.fill();
 
 
135
  });
136
 
137
+ // Optionally draw food with red paper pattern
138
+ if (this.resources.food > 0) {
139
  this.ctx.fillStyle = this.patterns.food();
140
  this.ctx.fillRect(50, 50, 16, 16); // Example position for food
141
  }