فهرست منبع

adding swarm concept for bee teams

Justin Gilman 4 سال پیش
والد
کامیت
361655c502
3فایلهای تغییر یافته به همراه25 افزوده شده و 2 حذف شده
  1. 15 0
      js/Bee.js
  2. 7 1
      js/Hive.js
  3. 3 1
      js/main.js

+ 15 - 0
js/Bee.js

@@ -15,6 +15,7 @@ export class Bee {
         this.homeHive = null;
         this.targetObject = null;
         this.carryingHoney = 0;
+        this.swarm = 0;
     }
     static async loadGeo() {
         return new THREE.IcosahedronBufferGeometry(3, 0);
@@ -50,6 +51,20 @@ export class Bee {
         this.homeHive = homeHive;
     }
 
+    setSwarm(id) {
+        this.swarm = id;
+        switch (this.swarm) {
+            case 2:
+                this.model.material.color.set(0xff0000);
+                break;
+
+            case 1:
+            default:
+                this.model.material.color.set(0xffff00);
+                break;
+        }
+    }
+
     setPosition(x, y, z) {
         this.position.x = x;
         this.position.y = y;

+ 7 - 1
js/Hive.js

@@ -17,6 +17,7 @@ export class Hive {
         this.entranceWaypoint = null;
         this.billboard = null;
         this.yWobble = 0;
+        this.swarm;
     }
     static loadModel() {
         return new Promise((resolve, reject) => {
@@ -51,7 +52,6 @@ export class Hive {
         this.position.x = (70 * i) - 70;
         this.position.z = Math.abs((20 * i) - 20);
         this.rotation.y = ((Math.PI / 4)) - ((Math.PI / 4) * i);
-        Hive.collection.push(this);
         this.entranceWaypoint = Waypoint.addNewHive(this.scene, this);
         this.billboard.position.set(this.position.x, this.position.y + 100, this.position.z);
         this.billboard.scale.set(this.billboardCanvas.width / 10, this.billboardCanvas.height / 10, 1);
@@ -112,6 +112,7 @@ export class Hive {
             let newBee = new Bee();
             newBee.model = Bee.baseModel.clone();
             newBee.init();
+            newBee.setSwarm(this.swarm);
             newBee.setHive(this);
             newBee.setPosition(this.position.x, this.position.y, this.position.z);
             newBee.setLastPosition(this.position.x, this.position.y, this.position.z);
@@ -131,6 +132,7 @@ export class Hive {
             if (!nextHive) {
                 return;
             }
+            newBee.setSwarm(this.swarm);
             newBee.setHive(nextHive);
             newBee.setPosition(this.position.x, this.position.y, this.position.z);
             newBee.setLastPosition(nextHive.position.x, nextHive.position.y, nextHive.position.z);
@@ -149,4 +151,8 @@ export class Hive {
             this.entranceWaypoint.removeLine(flower);
         }
     }
+
+    setSwarm(id) {
+        this.swarm = id;
+    }
 }

+ 3 - 1
js/main.js

@@ -122,6 +122,7 @@ function fillScene() {
             let hive = new Hive(scene);
             await hive.load(result[0]);
             hive.init(i);
+            Hive.collection.push(hive);
         }
 
         Hive.collection.forEach(hive => hive.addToScene(scene));
@@ -137,7 +138,6 @@ function fillScene() {
             if (i == 0) {
                 flower.position.x = 0;
                 flower.position.z = 100;
-                Hive.collection[1].toggleFlower(flower);
             }
             else {
                 // let randomHive = Hive.collection[Math.floor(Hive.collection.length * Math.random())];
@@ -150,6 +150,8 @@ function fillScene() {
         Flower.collection.forEach(flower => flower.addToScene(scene));
 
         Bee.baseModel = result[2];
+        Hive.collection[1].setSwarm(1);
+        Hive.collection[1].toggleFlower(Flower.collection[0]);
         Hive.collection[1].spawnBee();