Terrain Generation
^^create a 64 x 64 block, no need to place in room. keep default room dimensions 1024 x 768. this all means we have a grid of 1024 / 64 = 16 block spaces x 768 / 64 = 12 block spaces to work with
Creation Code (for room0):
//max / min height (in blocks):
maxHeight = 9;
minHeight = 3;
//to calculate height and width of grid, got to
//spawn an instance of the block first:
temp = instance_create_layer(0,0,"Instances",objBlock);
blockHeight = objBlock.sprite_height;
blockWidth = objBlock.sprite_width;
gridHeight = room_height / blockHeight;
gridWidth = room_width / blockWidth;
instance_destroy(temp);
//co-ords for our first block:
randomize();
xx = 0;
yy = irandom_range(gridHeight - maxHeight, gridHeight - minHeight);
//go across the screen...
for(columnToFill = xx; columnToFill <= gridWidth; columnToFill += 1){
//... work out up one, same height or down one for each column...
upSameDown = irandom_range(1,3); //1 up, 2 same height, 3 down
switch(upSameDown){
case 1: if(yy > (gridHeight - maxHeight))yy -= 1; break;
case 2: break; //do nothing - same height!
case 3: if(yy < (gridHeight - minHeight))yy += 1; break;
}
//...and fill each column to the ground:
for(columnPos = yy; columnPos <= gridHeight; columnPos += 1){
instance_create_layer(columnToFill * blockWidth, columnPos * blockHeight, "Instances", objBlock);
}
}
Creation Code (for game maker 8.1 lite users):
//max / min height (in blocks):
maxHeight = 9;
minHeight = 3;
//to calculate height and width of grid, got to
//spawn an instance of the block first:
temp = instance_create(0,0,objBlock);
blockHeight = objBlock.sprite_height;
blockWidth = objBlock.sprite_width;
gridHeight = room_height / blockHeight;
gridWidth = room_width / blockWidth;
with (temp) instance_destroy();
//co-ords for our first block:
randomize();
xx = 0;
yy = irandom_range(gridHeight - maxHeight, gridHeight - minHeight);
//go across the screen...
for(columnToFill = xx; columnToFill <= gridWidth; columnToFill += 1){
//... work out up one, same height or down one for each column...
upSameDown = irandom_range(1,3); //1 up, 2 same height, 3 down
switch(upSameDown){
case 1: if(yy > (gridHeight - maxHeight))yy -= 1; break;
case 2: break; //do nothing - same height!
case 3: if(yy < (gridHeight - minHeight))yy += 1; break;
}
//...and fill each column to the ground:
for(columnPos = yy; columnPos <= gridHeight; columnPos += 1){
instance_create(columnToFill * blockWidth, columnPos * blockHeight, objBlock);
}
}

