Solved

Generating a random map in C or C++

Posted on 2000-04-20
8
515 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
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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to address a class using javah; or, what are fully-qualified java class names? 13 86
Getting IP address 8 89
Header of docx file 17 118
FMX TCameraComponent Problem 2 89
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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…
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 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.

820 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