The hardest part about learning blueprint is that the vast majority of source and reference material is in Java or similar. I am not a programmer…
Can anyone help finish converting the below Java to BP? I think I understand most of it, but some parts I don’t yet know how to work out in BP. Any help would be appreciated!
Below is my current progress. The problems I think I am left with are;
What is “nearest” and how do I handle it?
How do I “set the field”?
How do I “print the field”?
So the first part I think matches the Java pretty well, minus the fact that I don’t know what to do with “char nearest”.
http://img.photobucket.com/albums/v129/Decimatus/Biome1.png
The second part seems pretty good minus the “nearest” and field setting/printing sections that I am not sure how to handle. Also, this is only showing 1 biome, so the rest would slide alongside the desert biome as needed.
http://img.photobucket.com/albums/v129/Decimatus/Biome2.png
Here is the source Java:
// a simple 'struct' to hold some vars
class BiomeInfo {
char type;
int x;
int y;
}
//next we set up some points. You can add random to this task and also add any type multiple times
char[][] field = new field[32][32];
biomeInfo[0].type = '#';
biomeInfo[0].x = 5;
biomeInfo[0].y = 5;
//next: walk over the field
for (int i = 0; i < field.length; i++) {
for (int j = 0; j < field[0].length; j++) {
char nearest = '.'; // value here doesn't matter
int dist = Integer.MAX_VALUE; // select a big number
// walk over each biomeInfo
for (int z = 0; z < biomeInfo.length; z++) {
// calculate the difference in x and y direction
int xdiff = biomeInfo[z].x - i;
int ydiff = biomeInfo[z].y - j;
// calculate euclidean distance, sqrt is not needed
// because we only compare and do not need the real value
int cdist = xdiff*xdiff + ydiff*ydiff;
// is the current distance smaller than the old distance?
// if yes, take this biome
if (cdist < dist) {
nearest = biomeInfo[z].type;
dist = cdist;
}
}
// set the field to the nearest biome
field[i][j] = nearest;
// you can mark the biome point with this code
// if (dist == 0) {
// field[i][j] = 'X';
// }
}
}
// print field:
for (int i = 0; i < field.length; i++) {
for (int j = 0; j < field[0].length; j++) {
System.out.printf("%c ", field[i][j]);
}
System.out.printf("%n"); // %n means newline
}
System.out.printf("%n");
An example print of what I am trying to achieve: