added tree methods and cottage_road example function.
This commit is contained in:
parent
15ce10f0e6
commit
8ba4e466c2
2 changed files with 75 additions and 4 deletions
56
cottage.js
56
cottage.js
|
@ -17,7 +17,7 @@ load($SCRIPT_DIR + "/drone.js"); // assumes cottage.js and drone.js are in same
|
||||||
//
|
//
|
||||||
// /js cottage(drone);
|
// /js cottage(drone);
|
||||||
//
|
//
|
||||||
var cottage = function(drone)
|
function cottage(/* optional */ drone)
|
||||||
{
|
{
|
||||||
if (typeof drone == "undefined"){
|
if (typeof drone == "undefined"){
|
||||||
drone = new Drone();
|
drone = new Drone();
|
||||||
|
@ -35,5 +35,57 @@ var cottage = function(drone)
|
||||||
|
|
||||||
return drone.move('cottage');
|
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);
|
|
||||||
|
|
23
drone.js
23
drone.js
|
@ -102,11 +102,21 @@ var Drone = {
|
||||||
box0: function(b,w,h,d){},
|
box0: function(b,w,h,d){},
|
||||||
prism: function(b,w,d){},
|
prism: function(b,w,d){},
|
||||||
prism0: 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)
|
// signs must use block 63 (stand-alone signs) or 68 (signs on walls)
|
||||||
// s can be a string or an array of strings.
|
// 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
|
// Implementation
|
||||||
|
@ -455,6 +465,15 @@ var Drone = {
|
||||||
that.y = s;
|
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;
|
ScriptCraft.Drone = Drone;
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
Reference in a new issue