We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Can someone please help me make a better cave generator? It would be much appreciated thank you.
void setup() {
size(800, 500);
}
void draw() {
}
void mouseClicked() {
gen();
}
void gen() {
background(0);
translate(width/2, height/2);
rotate(PI);
int w = 10, h = 10;
for (int i = -width/2; i < width; i += w) { //GROUND
for (int j = -height/2; j < int(random(0, h*2)); j += h) {
fill(127); //Rock
rect(i, j, w, h);
}
}
for (int i = -width/2; i < width; i += w) { //CAVE
for (int j = -height/2; j < int(random(0, h*2)); j += h) {
fill(0); //Cave
int caveChance = 1000;
int cave = int(random(caveChance + 1));
if (cave == caveChance) {
println(cave);
for (int k = 0; k < int(random(10, 25))*h; k += h) {
for (int l = 0; l < int(random(10, 25))*w; l += w) {
rect(i + l + int(random(10))*w, j + k + int(random(10))*h, w, h);
}
}
}
}
}
}
Answers
http://studio.ProcessingTogether.com/sp/pad/export/ro.9Ql2E8JBC54LJ
that is a birds eye view of a map, mine is a side view and it doesn't really help me figure out how to generate caves.
I guess the real question is... What makes a "better" cave? Like, how do you define a cave as "good" or "better" than some other cave?
Here cave generation algorithm using Celluar Automata (if you familliar with game of life that should be easy, or else, read Shiffman).
What I would like to happen is when the code generates the black tiles there are no gray spots in there with them. So more of a smooth and easily definable cave side if possible?
Thank you Ater I have figured out how to create the caves thanks to the links you sent :)
Amazing, makes me want to try to generate something too! :)
It's fun, but can get annoying if you don't think in multiples in the width and height of a single cell.
I'll be posting the final code on my Open Processing Port Folio later on this week hopefully.
http://www.openprocessing.org/user/50389
Version 1.0 http://www.openprocessing.org/sketch/267785