diff --git a/cottage.js b/cottage.js index b66086b..7ab764c 100644 --- a/cottage.js +++ b/cottage.js @@ -17,7 +17,7 @@ load($SCRIPT_DIR + "/drone.js"); // assumes cottage.js and drone.js are in same // // /js cottage(drone); // -var cottage = function(drone) +function cottage(/* optional */ drone) { if (typeof drone == "undefined"){ drone = new Drone(); @@ -35,5 +35,57 @@ var cottage = function(drone) return drone.move('cottage'); }; +// +// a more complex script that builds an tree-lined avenue with +// cottages on both sides. +// +function cottage_road(numberCottages,/* optional */ drone) +{ + if (typeof numberCottages == "undefined"){ + numberCottages = 6; + } + if (typeof drone == "undefined"){ + drone = new Drone(); + } + var i=0, distanceBetweenTrees = 11; + // + // step 1 build the road. + // + var cottagesPerSide = Math.floor(numberCottages/2); + drone + .chkpt("cottage_road") // make sure the drone's state is saved. + .box(43,3,1,cottagesPerSide*(distanceBetweenTrees+1)) // build the road + .up().right() // now centered in middle of road + .chkpt("cr"); // will be returning to this position later + + // + // step 2 line the road with trees + // + for (; i < cottagesPerSide+1;i++){ + drone + .left(5).oak() + .right(10).oak() + .left(5) // return to middle of road + .fwd(distanceBetweenTrees+1); // move forward. + } + drone.move("cr").back(6); // move back 1/2 the distance between trees + + // this function builds a path leading to a cottage. + function pathAndCottage(d){ + return cottage(d.down().box(43,1,1,5).fwd(5).left(3).up()); + }; + // + // step 3 build cottages on each side + // + for (i = 0;i < cottagesPerSide; i++) + { + drone.fwd(distanceBetweenTrees+1).chkpt("r"+i); + // build cottage on left + pathAndCottage(drone.turn(3)).move("r"+i); + // build cottage on right + pathAndCottage(drone.turn()).move("r"+i); + } + // return drone to where it was at start of function + return drone.move("cottage_road"); +} -print ("loaded " + $SCRIPT); diff --git a/drone.js b/drone.js index 83c300a..7721395 100644 --- a/drone.js +++ b/drone.js @@ -102,11 +102,21 @@ var Drone = { box0: function(b,w,h,d){}, prism: function(b,w,d){}, prism0: function(b,w,d){}, - door: function(b){}, + // miscellaneous + // ============= + + // create a door - if a parameter is supplied an Iron door is created otherwise a wooden door is created. + door: function(b){}, // signs must use block 63 (stand-alone signs) or 68 (signs on walls) // s can be a string or an array of strings. - sign: function(s,b){} + sign: function(s,b){}, + + // create trees. + oak: function(){}, + spruce: function(){}, + birch: function(){}, + jungle: function(){} }; // // Implementation @@ -454,6 +464,15 @@ var Drone = { } that.y = s; }; + + var _trees = {oak: 6 + ,spruce: '6:1' + ,birch: '6:2' + ,jungle: '6:3' + }; + for (var p in _trees){ + Drone.prototype[p] = function(v){return function(){ return this.box(v);};}(_trees[p]); + } ScriptCraft.Drone = Drone;