git @ Cat's Eye Technologies Cyclobots / d9c2cee
Remove onInitBot. Add functions to set/remove visuals on bots. Chris Pressey 3 years ago
2 changed file(s) with 30 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1616 var c = new Cyclobots().init({
1717 width: config.width,
1818 height: config.height,
19 onInitBot: function(bot) {
19 onUpdateBot: function(bot) {
20 if (!bot.graphics) return;
21 bot.graphics.x = bot.x;
22 bot.graphics.y = bot.y;
23 }
24 });
25
26 function removeVisuals(c) {
27 c.forEachBot(function(bot) {
28 if (bot.graphics) {
29 bot.graphics.destroy();
30 }
31 bot.graphics = undefined;
32 });
33 }
34
35 function setVisuals(c) {
36 c.forEachBot(function(bot) {
37 if (bot.graphics) return;
2038 var graphics = new PIXI.Graphics();
2139 graphics.lineStyle(0);
2240 graphics.beginFill(0xff0000);
2543 //graphics.filters = [new PIXI.filters.BlurFilter()];
2644 app.stage.addChild(graphics);
2745 bot.graphics = graphics;
28 },
29 onUpdateBot: function(bot) {
30 bot.graphics.x = bot.x;
31 bot.graphics.y = bot.y;
32 }
33 });
46 });
47 }
48
49 setVisuals(c);
3450
3551 app.ticker.add(function(delta) {
3652 c.update();
8197 panel.innerHTML += ' <a href="?forceCanvas=1">Force Canvas renderer</a>.';
8298 }
8399 }
100 function makeVisualsPanel(container) {
101 var panel = makeDiv(container);
102 makeButton(panel, "Classic", function(e) { setVisuals(c); });
103 makeButton(panel, "Remove", function(e) { removeVisuals(c); });
104 }
84105
85106 var controlPanel = makeDiv(config.container);
86107 var rendererPanel = makeRendererPanel(controlPanel);
108 var visualsPanel = makeVisualsPanel(controlPanel);
87109 makeButton(controlPanel, "Mass confusion!", function(e) { c.massConfusion(); });
88110 makeButton(controlPanel, "Revolution!", function(e) { c.shuffle(); });
89111 }
88 this.speed = config.speed;
99 this.dexterity = config.dexterity; // radians
1010 this.next = config.next;
11 if (config.onInitBot) {
12 config.onInitBot(this);
13 }
1411 return this;
1512 };
1613
6057 y: 50 + Math.random() * (config.height - 100),
6158 theta: Math.random() * TWO_PI,
6259 speed: 2,
63 dexterity: 2 * RADIANS_PER_DEGREE,
64 onInitBot: config.onInitBot
60 dexterity: 2 * RADIANS_PER_DEGREE
6561 });
6662 this.bots.push(bot);
6763 }