16 | 16 |
var c = new Cyclobots().init({
|
17 | 17 |
width: config.width,
|
18 | 18 |
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;
|
20 | 38 |
var graphics = new PIXI.Graphics();
|
21 | 39 |
graphics.lineStyle(0);
|
22 | 40 |
graphics.beginFill(0xff0000);
|
|
25 | 43 |
//graphics.filters = [new PIXI.filters.BlurFilter()];
|
26 | 44 |
app.stage.addChild(graphics);
|
27 | 45 |
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);
|
34 | 50 |
|
35 | 51 |
app.ticker.add(function(delta) {
|
36 | 52 |
c.update();
|
|
81 | 97 |
panel.innerHTML += ' <a href="?forceCanvas=1">Force Canvas renderer</a>.';
|
82 | 98 |
}
|
83 | 99 |
}
|
|
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 |
}
|
84 | 105 |
|
85 | 106 |
var controlPanel = makeDiv(config.container);
|
86 | 107 |
var rendererPanel = makeRendererPanel(controlPanel);
|
|
108 |
var visualsPanel = makeVisualsPanel(controlPanel);
|
87 | 109 |
makeButton(controlPanel, "Mass confusion!", function(e) { c.massConfusion(); });
|
88 | 110 |
makeButton(controlPanel, "Revolution!", function(e) { c.shuffle(); });
|
89 | 111 |
}
|