Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Generating a random map in C or C++

Posted on 2000-04-20
8
Medium Priority
?
529 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Accepted Solution

by:
forza earned 200 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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