Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
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 1304 times)
0 Members and 1 Guest are viewing this topic.
Offline Czar815

Senior Newbie


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


Mathematician/Musician/Programmer


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


Medals: 49
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: 342
Projects: 6
Exp: 6 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: 4
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:

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="http://www.youtube.com/v/YbxgCuxW2Pg?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/YbxgCuxW2Pg?version=3&amp;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  
 
 

 
cybrmynd (137 views)
2017-08-02 12:28:51

cybrmynd (157 views)
2017-08-02 12:19:43

cybrmynd (150 views)
2017-08-02 12:18:09

Sralse (167 views)
2017-07-25 17:13:48

Archive (640 views)
2017-04-27 17:45:51

buddyBro (762 views)
2017-04-05 03:38:00

CopyableCougar4 (1295 views)
2017-03-24 15:39:42

theagentd (1262 views)
2017-03-24 15:32:08

Rule (1235 views)
2017-03-19 12:43:22

Rule (1310 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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
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!