I just made a code that reads a text document, and makes terrain based on it. An example of what it would read is:
11111
12221
12321
12221
11111
It reads each number and builds that many high, so that following example would be a somewhat like a pyrimid. Now my question is, how could I make a script that would generate the text files for me, and be somewhat realistic instead of just random spikes? Heres the script that reads and makes the terrain:
function makeMap(%map)
{
%file = new fileObject();
%file.openForRead("add-ons/chat_c/terrain/" @ %map @ ".txt");
while(!%file.isEOF())
{
%line = %file.readLine();
%len = strlen(%line);
for(%i=1;%i<%len;%i++)
{
%char = getsubstr(%line,%i,1);
for(%up=0;%up<%char;%up++)
{
plantBrick(1);
plantBrick(0);
superShiftBrickUp(1);
superShiftBrickUp(0);
}
for(%down=0;%down<%char;%down++)
{
superShiftBrickDown(1);
superShiftBrickDown(0);
}
superShiftBrickRight(1);
superShiftBrickRight(0);
}
superShiftBrickAway(1);
superShiftBrickAway(0);
for(%i=1;%i<%len;%i++)
{
superShiftBrickLeft(1);
superShiftBrickLeft(0);
}
}
%file.close();
%file.delete();
}
And heres the one that generates a text document to build, but its not very realistic.
function genMap(%x,%y,%map)
{
%lineNum = 1;
for(%mx=0;%mx<%x;%mx++)
{
%line = "";
for(%my=0;%my<%y;%my++)
{
%add = getRandom(1,5);
%line = %line @ %add;
}
%file = new fileObject();
%file.openForAppend("add-ons/chat_c/terrain/" @ %map @ ".txt");
%file.writeLine(%line);
%lineNum++;
%file.close();
%file.delete();
}
}