Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (808)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (872)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D Map Generator  (Read 8555 times)
0 Members and 1 Guest are viewing this topic.
Offline Czar815

Senior Newbie

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


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

Hello! My first post in the forum Cheesy

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

More shading in 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.
Offline dime26

JGO Wizard

Medals: 90
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.
Offline orange451

JGO Kernel

Medals: 571
Projects: 9
Exp: 8 years

Your face? Your ass? What's the difference?

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

Looks very pretty Smiley Can't wait to see more.

First Recon. A java made online first person shooter!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Czar815

Senior Newbie

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


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

Thanks for the feedback!


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

Screenshots (in hyperlink)

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.

Screenshots (in hyperlink)

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:

<a href=";hl=en_US&amp;start=" target="_blank">;hl=en_US&amp;start=</a>

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  

mercenarius (12 views)
2020-06-04 19:26:01

mercenarius (18 views)
2020-06-04 19:13:43

Riven (853 views)
2019-09-04 15:33:17

hadezbladez (5843 views)
2018-11-16 13:46:03

hadezbladez (2652 views)
2018-11-16 13:41:33

hadezbladez (6268 views)
2018-11-16 13:35:35

hadezbladez (1506 views)
2018-11-16 13:32:03

EgonOlsen (4742 views)
2018-06-10 19:43:48

EgonOlsen (5801 views)
2018-06-10 19:43:44

EgonOlsen (3292 views)
2018-06-10 19:43:20
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 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‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!