Announcement

Collapse
No announcement yet.

Random Terrain generation (like Minecraft)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Random Terrain generation (like Minecraft)

    Hey guys
    I wanted to ask if someone knows how to create or to program a "world generator".
    It should generate a world with special plants, rocks etc. which gets stuck on to the world that is already generated..(a bit like Minecraft i guess ^^)
    Does someone have some code or ideas or even links??

    #2
    Ok i found a website with some code...but I want it to be an open top level (forest,..etc.)
    But here is the code for the Dungeon kind of generater:
    Code:
    private function GenerateBranches()
    {
    	local int i;
    	local bool bSpawned;
     
    	`log("GENERATING BRANCH STRUCTURES...");
     
    	//Spawn the initial proxy branch to start the chain and avoid overlapping the root
    	NextBranchDirect = ROOM_Forward;
    	SpawnBranch();
    	NextRoomType = GetNextRoomType();
     
    	for(i=0; i<80; i++)
    	{
    		if(CheckRoomCollision(GetSpawnLocation(PreviousBranch, NextBranchDirect), false))
    		{
    			if(NextRoomType != ROOM_Small && !CheckReverseRoomCollision(GetSpawnLocation(PreviousBranch, NextBranchDirect), false))
    			{
    				PreviousBranch.DeleteAvailableRoom(NextBranchDirect);
    				bSpawned = false;
    				i--;
    			}else
    			{
    				bSpawned = true;
    				SpawnBranch();
    			}
    		}else
    		{
    			//`log("Room would collide with pre-existing one.  Generating new direction.");
    			PreviousBranch.DeleteAvailableRoom(NextBranchDirect);
    			bSpawned = false;
    			i--;
    		}
     
    		NextBranchDirect = CalculateBranchDirection();
     
    		if(bSpawned)
    			NextRoomType = GetNextRoomType();
     
    		if(NextBranchDirect == ROOM_None)
    		{
    			//`log("NextBranchDirect is ROOM_None.  Ending generation early.");
    			break;
    		}
    	}
    }
     
    private function GenerateLeaves()
    {
    	local int i, j, randNum;
    	local bool bSpawned;
     
    	`log("GENERATING LEAF STRUCTURES...");
     
    	for(i=0; i<BranchList.Length; i++)
    	{
    		randNum = FRand() * BranchList[i].GetNumAvailableRooms();
     
    		for(j=-1; j<randNum; j++)
    		{
    			if(!ShouldSkipThisLeaf())
    			{
    				NextLeafDirect = CalculateLeafDirection(BranchList[i]);
     
    				if(bSpawned)
    					NextRoomType = GetNextRoomType();
     
    				if(NextLeafDirect != ROOM_None)
    				{
    					if(CheckRoomCollision(GetSpawnLocation(BranchList[i], NextLeafDirect), true))
    					{
    						if(NextRoomType != ROOM_Small && !CheckReverseRoomCollision(GetSpawnLocation(BranchList[i], NextLeafDirect), true))
    						{
    							//`log("Room would collide with pre-existing one.  Skipping this leaf.");
    							bSpawned = false;
    							BranchList[i].DeleteAvailableRoom(NextLeafDirect);
    						}else
    						{
    							bSpawned = true;
    							SpawnLeaf(BranchList[i]);
    						}
    					}else
    					{
    						//`log("Room would collide with pre-existing one.  Skipping this leaf.");
    						bSpawned = false;
    						BranchList[i].DeleteAvailableRoom(NextLeafDirect);
    					}
    				}else
    				{
    					//`log("NextLeafDirect is ROOM_None.  Skipping this leaf.");
    					bSpawned = false;
    				}
    			}else
    			{
    				//`log("ShouldSkipThisLeaf roll returned true.  Skipping this leaf.");
    				bSpawned = false;
    			}
    		}
    	}
    }

    Comment


      #3
      Originally posted by scrapland View Post
      Ok i found a website with some code...but I want it to be an open top level (forest,..etc.)
      But here is the code for the Dungeon kind of generater:
      Wow thanks for this! Where did you find this exactly? i want to use this ^^

      Comment


        #4
        Originally posted by BloodKnight64 View Post
        Wow thanks for this! Where did you find this exactly? i want to use this ^^
        Here:http://www.andrewfranzen.com/unreals...geon-generator

        Comment


          #5
          Thanks. And from what he says you could try making a base area and set things like 'biomes' like minecraft. And replace what he makes rooms with your biomes. In theory it should work.

          Comment


            #6
            exactly!
            I will try that out now

            Comment


              #7
              Just so you know, that is only a snippet of the actual code. Imo, you should just make your own generator.

              Comment


                #8
                lol of course i know why should he put all of the code in ^^
                But the rest isn't that difficult anymore

                Comment

                Working...
                X