Skip to content

Instantly share code, notes, and snippets.

@Trinick
Last active December 20, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Trinick/6144856 to your computer and use it in GitHub Desktop.
Save Trinick/6144856 to your computer and use it in GitHub Desktop.
function buildTerrain(%x,%y,%m,%b)
{
for(%i=0;%i<%x;%i++)
{
for(%j=0;%j<%y;%j++)
{
%tile[%i,%j] = getRandom(-1,1);
}
}
for(%i=0;%i<%x;%i++)
{
for(%j=0;%j<%y;%j++)
{
for(%k=1;%k<=%m;%k++)
{
%height[%i,%j] += %tile[%i,%j];
%height[%i,%j] += %tile[%i-%k,%j]; //%tile1_2, %tile0_2
%height[%i,%j] += %tile[%i+%k,%j]; //%tile3_2, %tile4_2
%height[%i,%j] += %tile[%i,%j-%k]; //%tile2_1, %tile2_0
%height[%i,%j] += %tile[%i,%j+%k]; //%tile2_3, %tile2_4
}
}
}
for(%i=0;%i<%x;%i++)
{
for(%j=0;%j<%y;%j++)
{
%height = 0;
for(%k=1;%k<=%m;%k++)
{
%height += %height[%i,%j];
%height += %height[%i-%k,%j]; //%tile1_2, %tile0_2
%height += %height[%i+%k,%j]; //%tile3_2, %tile4_2
%height += %height[%i,%j-%k]; //%tile2_1, %tile2_0
%height += %height[%i,%j+%k]; //%tile2_3, %tile2_4
}
%height = %height/2;
if(%height < 0)
%color = 0;
else
%color = mAbs(mFloor(%height));
%lowestSurroundingX = (%height[%i-1, %j] > %height[%i+1,j]) ? %height[%i+1, %j] : %height[%i-1, %j];
%lowestSurroundingY = (%height[%i, %j-1] > %height[%i,j+1]) ? %height[%i, %j+1] : %height[%i, %j-1];
%lowestSurrounding = (%lowestSurroundingX > %lowestSurroundingY) ? %lowestSurroundingY : %lowestSurroundingX;
%down = mFloor((%height-%lowestSurrounding)/(%b.brickSizeZ*64)) + 1;
for(%down = 0; %down < %bricksDown, %down++) {
%brick = new fxDTSBrick()
{
colorID = %color;
printID = 82;
dataBlock = %b;
position = (%i*%b.brickSizeX/2) SPC (%j*%b.brickSizeY/2) SPC (100+(%height*(%b.brickSizeZ/64))-%down*;
isPlanted = 1;
height = %height;
X = %i;
Y = %j;
};
%brick.setTrusted(1);
%brick.plant();
BrickGroup_888888.add(%brick);
if(%down == 0)
$Terrain::Brick[%i,%j] = %brick;
}
}
}
}
//was using this to try out another method, decided to keep it in case of things
function getBetween(%a,%b,%x)
{
return %a*(1-%x)+%b*%x;
}
package terrainTestPackage
{
function Player::activateStuff(%player)
{
parent::activateStuff(%player);
%start = %player.getEyePoint();
%direction = %player.getEyeVector();
%path = vectorScale(%direction,5);
%stop = vectorAdd(%start,%path);
%ray = containerRayCast(%start,%stop,$TypeMasks::All,%player);
%col = firstWord(%ray);
if(!isObject(%col))
return;
if(%col.getClassName() $= "fxDTSBrick")
messageAll('',"\c2ID:\c6" SPC %col SPC "\c2Var: \c6$Terrain::Brick" @ %col.X @ "_" @ %col.Y SPC "\c2Height: \c6" @ %col.height);
}
};
activatePackage(terrainTestPackage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment