Introduce forEachBot().
Chris Pressey
6 years ago
69 | 69 | return this; |
70 | 70 | }; |
71 | 71 | |
72 | this.forEachBot = function(callback) { | |
73 | for (var i = 0; i < this.bots.length; i++) { | |
74 | callback(this.bots[i]); | |
75 | } | |
76 | }; | |
77 | ||
72 | 78 | this.linkUpBots = function() { |
73 | 79 | var numBots = this.bots.length; |
74 | 80 | for (var i = 0; i < numBots - 1; i++) { |
78 | 84 | }; |
79 | 85 | |
80 | 86 | 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) { | |
83 | 89 | bot.move(); |
84 | 90 | bot.adjust(); |
85 | if (this.onUpdateBot) this.onUpdateBot(bot); | |
86 | } | |
91 | if ($this.onUpdateBot) $this.onUpdateBot(bot); | |
92 | }); | |
87 | 93 | }; |
88 | 94 | |
89 | 95 | 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 | }); | |
93 | 99 | }; |
94 | 100 | |
95 | 101 | this.shuffle = function() { |