Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  Random Map Generation  (Read 9510 times)
0 Members and 1 Guest are viewing this topic.
Offline Pinguinpanic

Junior Member


Medals: 3



« Reply #30 - Posted 2012-01-07 17:20:05 »

Today was tree planting day. At first I was like, OKAY GIVE EVERY TILE A TREE WITH A CHANCE of 0.5, but that looked but ugly, so I thought of something else. I changed up my "Map generator" a bit so that instead of giving out "Tiles" it gives out a value between one and hundred, and I do the title choosing in my "TileGrid" class (which makes a lot more sense).

Now, to plant my trees, I seeded another world, and used the values of the mapgenerator to choose where to place trees. This way, just like I use the map generator to make water appear together, with sand at the edges, I now use it to make trees appear together, with bushes along the edges. It works pretty fine! Here is a screenshot of the world zoomed out:

As you can see the trees form nice little woods! Which is pretty cool.

I also split all the parameters of my map generation so that I can easily load different "prefabs" for different terrains, and I added another bit to the terrain creation, for more randomization, which is what I dubbed "Cliff" generation, it works kind of like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
    
//For the amount of times I want to add a "Cliff"
for(int i=0;i<cliftimes;i++)
    {
      //Choose random point
     pointX=genValue(WIDTH);
      pointY=genValue(HEIGHT);

      //Choose random "intensity" depending on the parameter "Clifmult"
     mult=genValue(clifmult);
      //For every point
     for(int x=0;x<WIDTH;x+=1)
      {
        for(int y=0;y<HEIGHT;y+=1)
        {
          int t=distance(x,y,pointX,pointY);
          //This time instead of doing the Cos( ), I do a 2/(.5*(t+1)), so it's basicly a formula of the shape 1/t, which results in a nice and high peek!
         value[x][y]+=(int)(5*mult*(2/(.5*(t+1)))+mult*5*(1/(t+1)*Math.sin(t/5+90)));  
        }
      }  
    }  

This piece of code makes it possible to create nice islands, here's an example of my island biome:

As you can see, the cliff script is still, pretty ugly, I circled in red the ugly sudden rock formations it creates so I will have to tweak that to make it better. My goal with this addition is to make it possible for cliffs to appear next to the water (So that I can later add pretty waterfalls), but it isn't working yet : (. I'm thinking of doing something with "Erosion", evening out the low slopes, and extremizing the high slopes, but I'll have to look into that

Here is my swamp "biome" which does look pretty:

It's "initialization" code looks something like this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
      //SWAMP
     case 3:
      //"random" multiplier, decides the randomness
     ranmult=50;
      //Laketimes and lakemult determines the number of "Lake" constructions (The Cos(t)-Cos(.5t)) itterations
     laketimes=12;
      lakemult=10;
      //Determines the amounts of cliffs, which is still 0 since they are ugly
     cliftimes=0;
      clifmult=0;
      //How many times to Anti-alias
     aatimes=5;
      break;

Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #31 - Posted 2012-01-07 17:56:51 »

:O That looks beautiful!

Offline Pinguinpanic

Junior Member


Medals: 3



« Reply #32 - Posted 2012-01-07 18:14:44 »

Nice.  Just need a bit of texture splatting and you're all set.
"Texture splatting" has also been added, but I just have graphics for all the edges (:
:O That looks beautiful!
Yes it does, here's a picture of it up close

Really happy with my the artwork, it's very enjoyable working with such quality sprites, crafted to my specifications.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #33 - Posted 2012-01-07 18:34:29 »

Finally! I really wanted a top-down 2D version of Minecraft and Terraria! Now we have all dimensions and angles covered! =D Really beautiful!

Myomyomyo.
Offline Pinguinpanic

Junior Member


Medals: 3



« Reply #34 - Posted 2012-01-09 17:20:34 »

I felt rather unhappy with my map generation, in terms of making it possible to create infinte maps with it, so I decided to try something completely else!
It's a bit based on what Damocles is doing, here is what the code about looks like to give an idea:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
  public double getAAPoint(int x, int y, int aa)
  {
    //Base case
   if (aa<=0) return getPoint(x,y);
    //Calculate a "stepsize", which is kind of like how big the cell I'm using is
   double stepsize=Math.pow(2,aa);
    //return the top left corner of my current rectangle and call this function again with a lower "aa" which results in a lower stepsize
   return(getPoint((int)(x/stepsize),(int)(y/stepsize))
           +getAAPoint(x,y,aa-1));
  }

  public int getPoint(int x, int y)
  {
    //Returns a seeded random variable, between 0 and 100
   return rand.random(x*x-y,100);
  }

So for example getAAPoint(x,y,7), would first take the value of the left upper corner of a 128x128 square (2^7-*), (As do all points in this rectangle!), next I do the same for the 64x64 square this is in, then for the 32x32 square it is in, then 16x16, 8x8, 4x4, 2x2 1x1. I think you'll get what I mean, although my explanation is really vague. At the moment it looks reallllly shitty Tongue, but I'm sure that with more work, and maybe a tad of AA it is going to look good:

The square structure is reaally easy to spot at the moment, but oh well! I'm thinking of maybe trying something like this with circles or something, although I have no idea how I would subdivide the map in circles, but it seems like a funny idea, and in my opinion, as a hobby, programming has to remain fun.
Offline Damocles
« Reply #35 - Posted 2012-01-09 17:36:57 »

try to have the value have more impact (bigger factor), the smaller the "stepsize" is.

Thus the large features having the lowest impact.

With some smoothing, it should look much better also, and removes the large seams along the
bigger squares.

Offline Pinguinpanic

Junior Member


Medals: 3



« Reply #36 - Posted 2012-01-10 22:44:35 »

I'm making progress! I will show my progress in pictures, because a picture speaks a thousand words and stuff:

That was my first step, within every square, I choose a point, and I then draw circles arround it using sin(distance to the point). This looks incredibly shitty! Hooray, but now we add another circle, in a smaller rectangle, half the size the other one, and we get the following:

So that's already looking a bit better, but still has a lot of jagged edges and uglyness, but I thought OH WHATEVER, JUST DO THAT A LOT OF TIMES AND I"LL SEE WHAT IT LOOKS LIKE.

Somehow it looks pretty good, don't ask me about the theory behind it. I'm now trying to aproximate how the map looked before with this new method. I think with some smoothing I can get pretty near, but I have so far not used smoothing.

The benefit of the new method is, that I just have a function getMapPoint(x,y) that returns the height of a point on the map, without requiring any prior knowledge on the map or anything. It's fast too! I'm still thinking about how I'm going to do the smoothing fast.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #37 - Posted 2012-01-10 23:22:17 »

Taking a regular shape and iterating it a bunch of times randomly = chaotic result.  Just what you want in terrain.

Actually if you applied a bit of erosion to the second map, you'd get a pretty nifty bog with lots of lagoons.
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (6 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!