Solved

Generating a random map in C or C++

Posted on 2000-04-20
8
520 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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