This repository has been archived on 2021-07-14. You can view files and clone it, but cannot push or open issues or pull requests.
scriptcraft/src/main/javascript/drone/rboxcall.js
2013-02-10 17:51:27 +00:00

33 lines
1,012 B
JavaScript

/**
* Iterates over each cube in a cubic region. For each cube has a chance to callback your
* function and provide a new drone to it.
*
* Parameters:
* callback - any function that accepts a drone as its first argument
* probability - chance to invoke your callback on each iteration
* width - width of the region
* height - (Optional) height of the region, defaults to width
* depth - (Optional) depth of the cube, defaults to width
*/
Drone.extend("rboxcall", function(callback, probability, width, height, depth) {
this.chkpt('rboxcall-start');
for(var i = 0; i < width; ++i) {
this.move('rboxcall-start').right(i);
for(var j = 0; j < depth; ++j) {
this.move('rboxcall-start').right(i).fwd(j);
for(var k = 0; k < height; ++k) {
if(Math.random()*100 < probability) {
callback.call(null, new Drone(this.x, this.y, this.z));
}
this.up();
}
}
}
this.move('rboxcall-start');
return this;
});