2

Allright, I'm working on a small game here in Java, and I am using this Simplex Noise generator I found online. The problem that I am facing, is this: I'm generating the world of my game like so:

int width = 100;
int height = 100;
world = new int[width * height];

SimplexNoise noise = new SimplexNoise();
for (int i = 0; i < world.length; i++) {
     int x = i % width; // what are the coordinates from i ?
     int y = i / width ;


     int frequency = 15; 


     float h = (float) noise.noise((float) x / frequency, (float) y / frequency); 

         if (h >= -1 && h <= 0) {
                world[x + y * width] = 0; // air tile

         }
         else if (h > 0 && h <= 1) {
                world[x + y * width] = 1; // test tile

         }

      }

which quite obviously gives me 2D noise. The end result looks like this: look

As far as I understand noise, 2D noise is for top-down games. The one I'm working on, is a side-scroller (like Terraria, Starbound, Crea and others), though. So I'd need a terragen to give me the topmost layer of the terrain, google tells me that is 1D noise, so here's the question: How to convert this 2D noise into a terrain-looking 1D noise?

Makerimages
  • 384
  • 6
  • 27
  • Can you draw a picture of what you want? Maybe you need something like [1D Perlin Noise] ? (https://raw.githubusercontent.com/kaini/noise/master/doc/perlin_1d.png – caulitomaz Oct 23 '15 at 17:43
  • Yup, that is exactly what I'd like. @caulitomaz – Makerimages Oct 23 '15 at 17:45
  • Maybe you don't need to convert it to 1D, just reimplement a 1D Simplex / Perlin noise instead of 2D. Please refer to: http://stackoverflow.com/questions/8798771/perlin-noise-for-1d – caulitomaz Oct 23 '15 at 17:49
  • @caulitomaz that's a fun SO, links me back to the PDF i got the Simplex class form :D – Makerimages Oct 23 '15 at 17:52
  • I think the most obvious problem with your implementation is that you are using a one-dimensional array and it makes it harder for you to think in terms of X and Y coordinates. If you abstract the coordinates to something like setPixel(x,y,color) it will make it much simpler! – caulitomaz Oct 23 '15 at 17:56
  • @caulitomaz I could transform the world array into a 2 dimensional one, but how would I rewrite the for loop then? – Makerimages Oct 23 '15 at 17:59
  • You wouldn't loop through all X and Y coordinates, probably through only one axis. Please read https://www.khanacademy.org/computing/computer-programming/programming-natural-simulations/programming-noise/a/perlin-noise and study the examples. They have exactly what you want, but you will need to refactor a lot. – caulitomaz Oct 23 '15 at 18:09

1 Answers1

0

Just make it a picture of height = 1. Done :)

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121