Okay i have just edited this post
I want to make a better world generation for my game and perlin noise generation seems to be the way to go however there are not much on the internet for java about it so can anyone help?
Okay i have just edited this post
I want to make a better world generation for my game and perlin noise generation seems to be the way to go however there are not much on the internet for java about it so can anyone help?
Well, that depends on what you define a biome. You can have a biome, which is just a way of defining what kinds of terrain are generated in a particular area or chunk of the world. But maybe it decides what kind of plants and trees are being generated or what kind of animals or mobs will be spawned. You’ve said you only want a sand biome and a grass biome. So I think you mean that the terrain or tiles in a chunk, will be grass or sand-only? In that case you only need to fill the array with either sand or grass, which can be done by using a for loop and set every index to sand or grass.
well lets start with a massive area covered in sand?
You could start with a base class called [icode]Biome[/icode] which contains a [icode]Tile[/icode] object that defines the base terrain and when the biome is created set all tiles to that base Tile object and the go from there
Basic Biome class
public class Biome {
private Tile[][] tilemap;
private Tile basetile;
public Biome(int width, int height, Tile basetile){
tilemap = new Tile[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
tilemap[x][y] = basetile;
}
}
this.basetile = basetile;
}
}
CopyableCougar4
I would like it random though?
Well then you are gonna need to do this:
public class Biome {
private Tile[][] tilemap;
private static Random random = new Random();
public Biome(int width, int height, ArrayList<Tile> possible){
tilemap = new Tile[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
tilemap[x][y] = possible.get(random.nextInt(possible.size() - 1);
}
}
}
}
Now if you wanted weighted chances that is much more involved.
CopyableCougar4
How do arraylist work? I can do arrays but not list?
also would that be the entire map or just a certain part? ( I want it a certain part
Your map can be like this
public class Map {
private Biome[][] biomes;
...
ArrayLists are basically just constantly growing and shrinking arrays.
// This is an example.
private ArrayList<String> stuff = new ArrayList<String>();
stuff.add("");
stuff.remove("");
// String in both parts of the constructor can be replaced by any class or array (ie. Integer, Float, String, Object, float[])
If the <> parts confuse you: http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ001
If there’s any thing I say that is helpful, feel free to appreciate it
CopyableCougar4
It sounds like you don’t have the basics of OOP down, as well as Java. I suggest going back to square one and learning about OOP design.
Very vague question
Ok, fair enough
That would be a start, you don’t go to a car mechanic and don’t bring the car
It seems you need to take a step back and learn basic Java before diving any further, or you will drown.
I learned ArrayLists but never had a use for them. So yes I will need to go back and have a look
but how would I generate a massive area covered in a certain tile? and it is also random
this is what i use for generating random tiles
// Random Generation
for (int i = 0; i < tileGenAmount; i++) {
for (int j = 0; j < tileGenAmount; j++) {
if(j == 0|| j == tileGenAmount -1 || i == 0 && j <= tileGenAmount || i == tileGenAmount -1 && j <= tileGenAmount){
if(map[j][i] == 0){
map[j][i] = 106;
}
}
randomMapNumber = r.nextInt(106);
if(map[j][i] == 0){
map[j][i] = randomMapNumber;
}
}
}
public class Biome {
private Tile[][] tilemap;
private static Random random = new Random();
public Biome(int width, int height, ArrayList<Tile> possible){
tilemap = new Tile[width][height];
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
tilemap[x][y] = possible.get(random.nextInt(possible.size() - 1);
}
}
}
}
Now if you wanted weighted chances that is much more involved.
CopyableCougar4
[/quote]
What is the possible for?
It’s a list of all available tiles. In your case, it will only contain grass and sand.
But the thing I don’t get, is that you want a whole area covered in the same tile, but you want it random? If you fill a whole chunk with grass only, then there is no random factor involved. So could you please explain a bit more what you are trying to achieve here? And going back to look at some basic Java stuff will help a lot, before you start on some more difficult stuff like this.
Okay you know how minecraft generates its land (chunks) I want to do a similar thing. I want to create a area what is covered in sand but is on a random spot on the map and the same for grass if that makes any sense?
Yeah, now I get it. I think you want to have a look at Simplex or Perlin noise. That way you can generate small islands of grass, while the rest of the area is covered in sand.
LostWarrior has the right idea. You will need some sort of noise function. But FIRST: Learn Java.
I shall look at it. I do know java but forgot 1 thing because i dont use them
You are definitely going to need them in this project, there is almost no way around it. At least not a very reliable way. There are, by the way, plenty of good tile/chunk/generation tutorials on the web. You want to have a look at noise and weights for generation.
Could you send me a youtube tut so i know what to look for please?
I don’t really know any youtube tutorials, but there are plenty of text tutorials. Have a look at the Unity forum. It doesn’t supply you with Java code, but you will learn about the basic concepts.