xxxxxxxxxx
/*This is my random worls generator in processing(Terraria style)
i will not be putting comments all over the code, because i have other sketches that have that
and also i want to keep this code clean
this code works best in procesing, so i'd advise you to copy it into your PDE
if you have any questions about the code or something else, please don't hesitate to write a comment
i will respond as fast as i can*/
int[][] random_world = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
void setup(){
size(400, 400);
noStroke();
for(int i=1;i<11;i++){
for(int j=1;j<11;j++){
random_world[i][j]=random_world[i][j-1]==1?2:random_world[i][j-1]==3?2:random_world[i][j+1]==2?1:random_world[i][j-1]==2?int(random(2, 3.1)):random_world[i][j]==0?int(random(0, 1+(j/3))):0;
}
}
}
void draw(){
background(0, 150, 255);
for(int i=1;i<11;i++){
for(int j=1;j<11;j++){
fill(random_world[i][j]==2?204:0, random_world[i][j]==1?255:random_world[i][j]==2?204:0, random_world[i][j]==2?204:random_world[i][j]==3?150:random_world[i][j]==4?255:0, random_world[i][j]==1?255:random_world[i][j]==2?255:random_world[i][j]==3?255:random_world[i][j]==4?255:0);
rect((i-1)*40, (j-1)*40, 40, 40);
}
}
fill(0);
text("click R to generate a new world", 5, 15);
}
void keyPressed(){
if(key=='r'&&keyPressed){
for(int i=1;i<11;i++){
for(int j=1;j<11;j++){
random_world[i][j]=0;
}
}
setup();
}
}