Solved

Generating a random map in C or C++

Posted on 2000-04-20
8
506 Views
Last Modified: 2008-02-26
I want to design a random map generator for a game I am developping with some friends. Can anyone point some website where I could find tutorials or tips on that.
I could use a fractal design fonction but we have to set the percentage of land/water/mountains.... and I don't know how I could do it with a fractal function.....

So if anyone has tips and stuff, just tell me.......
0
Comment
Question by:David MacDonald
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:ntdragon
ID: 2735372
i"ll give an idea that i and my friend used in our simulator

write a func that reads bmp<or any other format>
and gives hight depending on the color
you"ll get very good map<i did it if you want i can send you the simulator and you see it your self but you need opengl installed on your comp>
as you see it 3D map

and you can change maps by changing the bmp

another one is random 2D map <you can make 3D by the same idea>
take "/" ,"\" and "_" lines and put random one or the other till you get a close map
example:

  /\
 /  \/\
/  _ _ \
\/
 
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 2741167
Well, unfortunatly, I don't have openGl, but the bmps you use are they randomly colored?
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2742332
you see it an idea you can it and implament it where ever you want

this will give you a moutained map
the you can color it or texture it randomlly as you wish
or you can create a few in paint brush
and to use them
as you know in games they use static maps not random maps
you i whould make some i paint brush
and make an opetion to choose a map

but that you should decide for yourself
0
 

Accepted Solution

by:
forza earned 50 total points
ID: 2772219
Try random midpoint displacement. It's a fractal algorithm that works like this (2D example):

1) Take a line segment.
2) Find the point P which divides in into two pieces of equal length.
3) Now move P a random distance in the vertical direction.
4) Repeat step 2-3 for each of the new line segments until you reach the desired resolution.

This will give you a very nice fractal landscape in 2D. To extend to 3D just apply the algorithm on a sqare grid (or better a triangle grid).
You can download a program that do this on my homepage: http://www.geocities.com/SiliconValley/Network/3958/flg.html

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:David MacDonald
ID: 2773411
Pretty cool program, and bike pictures too...:)

But how do you determine your line segment? is it random in the screen?

And do you have any suggestions for regrouping the elements(water, mountains, plains...) whilw generating the map?
0
 

Expert Comment

by:forza
ID: 2773631
Thanx
It's a bit hard to explain in words, so I just found a nice description with pictures: http://www2.vo.lu/homepages/phahn/fractals/plasma.htm

It's definitely the best algorithm for really random fractal landscapes.
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 2777066
Adjusted points from 30 to 50
0
 
LVL 1

Author Comment

by:David MacDonald
ID: 2777067
Thanx forza!!

I'll try the midpoint displacement, it looks like the best way for my needs... If you have any other link that would help, you can post them...anyway, thanks again...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now