Reduce an X/Y Value to an Index In a 1D array and Return the Array Value
From a short review;

the tilescale is 16 which is a great value to multiply or divide with, so
x = x/tilescale;
z = z/tilescale;

can become
x = x &gt;&gt; 4; //Divide by 16 (tilescale)
z = z &gt;&gt; 4; //Divide by 16 (tilescale)

this does mean that changing the tilescale can become a performance drag (like in real games)

So are 256 and 4, so
return(mapcol[(x+z*mapscalex)]*tilescaley);

could be
return(mapcol[(x+z&lt;&lt;8)]&lt;&lt;2); //Nice comment here


~~ is faster than Math.floor() but for negative values it does return ~~-6.3 -&gt; 6

Don't count on Math to be fast, I dont think I've ever seen Math be faster in anything, even an if statement is faster than Math.max(0,Math.floor(x))

When you know that x or z are either negative or greater than 255, why not just exit with a fixed value?

Check out 8 bit arrays, they might reduce the need for clamping in your code