Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (768) Games in Android Showcase (230) games submitted by our members Games in WIP (854) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 2D Map Generator  (Read 4529 times) 0 Members and 1 Guest are viewing this topic.
Czar815

Senior Newbie

Medals: 5
Projects: 1
Exp: 4-6 months

Mathematician/Musician/Programmer

 « Posted 2017-07-01 22:24:18 »

Hello! My first post in the forum

I believe I'm doing lots of stuff in a not optimum way, but I'm learning. My idea is create a game with RPG characteristics, but to be sincere, I have not planned how everything is going to work yet. I know that planning is very important when starting a new project, but I'm still learning most of the stuff I'm trying to do.

So, about what I've done so far. I have a basic 2D engine with window, input, renderer, etc. What I'm working most of my time is the 2D map generator.

I'm using the SimplexNoise class from JOML to create a height map. My map has dimensions "width x height", but my height map has dimension (width + 1) x (height + 1) for the following reason: each pixel of the final map is generated by 4 pixels of the height map. Why? Well, because I'm simulating a lighting shader. It works like this: for the pixel in the position (x,y), I'll take the height map pixels of position (x,y), (x+1,y), (x,y+1), (x+1,y+1). From this I calculate the gradient vector of the map pixel and then the normal vector. I use a "Sun vector" as reference for the light direction for computing the lighting of each pixel.

Later, I use the average of the height map values of the pixels (x,y), (x+1,y), (x,y+1), (x+1,y+1) to define the height of the pixel in the final map. I give a base color to that pixel based on its height and then apply the lighting.

Screenshots of the developing (in hyperlink for saving space in the board):

That darker green area is where a forest should be

Same, with random generated fog

After that, I wanted to add random generated trees to the darker green spots. I used a method that I found for generating islands height maps. Basically, each tree is a very small island.

Screenshots of the developing (in hyperlink for saving space in the board):

Trying to create a random generated tree

Using height map to generate the leaves

Now the edges blend into the background

Working the up scaling...

...and the down scaling. Testing the variation.

Testing the placement (size/distribution): bigger trees

Testing the placement (size/distribution): smaller trees

I can say that the final result was satisfactory.

Next (small) steps:
• Created island as terrain: using similar method used to create the trees;
• Simulate a daytime lighting: more orange at dawn, cold blue at night, brighter at midday, etc

Opinions & suggestions are very welcome!

by Czar815.
dime26

JGO Ninja

Medals: 72
Projects: 7
Exp: 12 years

Should traffic wardens be armed?

 « Reply #1 - Posted 2017-07-01 23:34:21 »

Looks good so far, I wouldnt worry too much about optimizing your code while you are learning and experimenting, there is always time to refactor later.
orange451

JGO Kernel

Medals: 438
Projects: 7
Exp: 7 years

 « Reply #2 - Posted 2017-07-02 02:59:42 »

Looks very pretty Can't wait to see more.

First Recon. A java made online first person shooter!
Czar815

Senior Newbie

Medals: 5
Projects: 1
Exp: 4-6 months

Mathematician/Musician/Programmer

 « Reply #3 - Posted 2017-07-02 17:41:39 »

Thanks for the feedback!

Update:

I was able to accomplish the next steps set in the original post:

First, I did the island generation thing.

Then I realized that map in particular kind of looked like Europe/Asia, don't you think? xD

After that, I went for the dynamic lighting stuff. I created a Sun class, which will hold the "time" of the world and from it, generate a vector from where the light is coming. I now use that to make the lighting shader. The sun also holds a "color scale" which gives the shader a specific color to each time. I simply overlay that color in every pixel.

Creating the island stuff messed with the normal maps. Notice how, for the normal map, the map is not a island.

Fixed it!

I also made a video show how the lights are working in that map:

For me the results were great, but I lost some of the performance. Curiously, the FPS at night time is higher than a day time, I don't know why.

Next steps:
• Dynamic shadows: I don't know how hard it will be, but looks not that easy.
• Redo the trees: and also try to make them drop shadow in the map.

by Czar815.
Pages: [1]
 ignore  |  Print

 EgonOlsen (1340 views) 2018-06-10 19:43:48 EgonOlsen (1230 views) 2018-06-10 19:43:44 EgonOlsen (939 views) 2018-06-10 19:43:20 DesertCoockie (1380 views) 2018-05-13 18:23:11 nelsongames (1112 views) 2018-04-24 18:15:36 nelsongames (1375 views) 2018-04-24 18:14:32 ivj94 (2120 views) 2018-03-24 14:47:39 ivj94 (1269 views) 2018-03-24 14:46:31 ivj94 (2286 views) 2018-03-24 14:43:53 Solater (808 views) 2018-03-17 05:04:08
 Deployment and Packagingby mudlee2018-08-22 18:09:50Java Gaming Resourcesby gouessej2018-08-22 08:19:41Deployment and Packagingby gouessej2018-08-22 08:04:08Deployment and Packagingby gouessej2018-08-22 08:03:45Deployment and Packagingby philfrei2018-08-20 02:33:38Deployment and Packagingby philfrei2018-08-20 02:29:55Deployment and Packagingby philfrei2018-08-19 23:56:20Deployment and Packagingby philfrei2018-08-19 23:54:46
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org