git @ Cat's Eye Technologies Cyclobots / ff0e8ac
Introduce forEachBot(). Chris Pressey 6 years ago
1 changed file(s) with 13 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
6969 return this;
7070 };
7171
72 this.forEachBot = function(callback) {
73 for (var i = 0; i < this.bots.length; i++) {
74 callback(this.bots[i]);
75 }
76 };
77
7278 this.linkUpBots = function() {
7379 var numBots = this.bots.length;
7480 for (var i = 0; i < numBots - 1; i++) {
7884 };
7985
8086 this.update = function() {
81 for (var i = 0; i < this.bots.length; i++) {
82 var bot = this.bots[i];
87 var $this = this;
88 this.forEachBot(function(bot) {
8389 bot.move();
8490 bot.adjust();
85 if (this.onUpdateBot) this.onUpdateBot(bot);
86 }
91 if ($this.onUpdateBot) $this.onUpdateBot(bot);
92 });
8793 };
8894
8995 this.massConfusion = function() {
90 for (var i = 0; i < this.bots.length; i++) {
91 this.bots[i].theta = Math.random() * TWO_PI;
92 }
96 this.forEachBot(function(bot) {
97 bot.theta = Math.random() * TWO_PI;
98 });
9399 };
94100
95101 this.shuffle = function() {