Solved

Generating a random map in C or C++

Posted on 2000-04-20
8
501 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

744 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

13 Experts available now in Live!

Get 1:1 Help Now