Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (600)
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  
  Randomly Generated Terrain  (Read 2969 times)
0 Members and 1 Guest are viewing this topic.
Offline duce

Senior Newbie





« Posted 2011-11-24 03:23:27 »

Hey, I'm working on a simple 2D Terraria clone game. I have a variable called "groundHeight", which controls the highest block of grass/dirt that will spawn on that column. I have that set to a Random.nextInt(), which works pretty well, but I want to have it more smooth between the columns. Right now, it looks very jagged from column to column. Is there a better way to do this, or a way to fix this smoothing?
Offline Mads

JGO Ninja


Medals: 26
Projects: 3
Exp: 6 years


One for all!


« Reply #1 - Posted 2011-11-24 03:41:43 »

Couldn't you make rough steps of random parabolas in your terrain? That should get more hilly.

Offline sproingie

JGO Kernel


Medals: 202



« Reply #2 - Posted 2011-11-24 04:19:30 »

You want perlin noise.  I'd add links, but google can do waaaaay better than me.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gbeebe

Senior Devvie


Medals: 5
Projects: 1



« Reply #3 - Posted 2011-11-24 04:25:12 »

In the game I'm working on, I spaced out the points that I randomize and then just "connected the dots". 
Screenshot: https://twitter.com/#!/gary_beebe/media/slideshow?url=pic.twitter.com%2F9erkaAMH

In your case it might be easier to randomly pick 0 or 1, 0 meaning that the next section is the next row down from the last section and 1 being the next row up.  That will be your groundHeight for the next couple of columns which you can randomize how long the section is (in columns), maybe ranging from 1 to 10.  This would probably give you a landscape similar to this:
http://terraria-servers.webs.com/terraria-steam-wiki.png
Offline sproingie

JGO Kernel


Medals: 202



« Reply #4 - Posted 2011-11-24 04:30:47 »

Spacing out random points and "connecting the dots" using something like cosine interpolation is pretty much the definition of perlin noise (I'm not clear on what I'd call the interpolation, it's certainly not linear).  You should definitely look it up -- it's not that hard to implement, and there are a lot of perlin heightmap generators that are ready-to-use that you can more or less drop in.
Offline gbeebe

Senior Devvie


Medals: 5
Projects: 1



« Reply #5 - Posted 2011-11-24 04:51:08 »

@sproingie After looking up Perlin Noise, I guess what I've been using is Linear Interpolation.  I've been looking for a way to smooth out the landscape and I think Cubic Interpolation could be very cool in a game like mine.  (Thanks for adding that to my vocabulary).

Here's a good article:
http://freespace.virgin.net/hugo.elias/models/m_perlin.htm
Offline Roquen
« Reply #6 - Posted 2011-11-24 07:28:56 »

Note: that web page is actually value noise and not Perlin.
Offline gbeebe

Senior Devvie


Medals: 5
Projects: 1



« Reply #7 - Posted 2011-11-25 00:53:55 »

Either way, I still appreciate you pointing it out.
Offline duce

Senior Newbie





« Reply #8 - Posted 2011-11-25 02:57:36 »

Thanks so much, guys! What I did was very simple. All of my "columns" have ids, the first ever column has an id of 0. I have an ArrayList of columns. I have it check the ArrayList for columns. If the column being generated has an id of less than 0, i check columns with a greater id and compare the generation, and vice versa. I then take that groundHeight, and add or subtract 1 (maybe more in the future), or keep it the same, by random. This works great for now.
Offline Lordpomeroy

Junior Devvie


Medals: 1
Projects: 1



« Reply #9 - Posted 2011-11-27 08:40:41 »

Maybe this aritcle will help you a little bit: http://javacooperation.gmxhome.de/LandscapeEng.html
I think it is a pretty simple way to generate 2D Terrain
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kaffiene
« Reply #10 - Posted 2011-11-27 23:23:41 »

use fractional brownian motion (fBm).  It's based on a Noise function (Perlin noise is fine) but gives you more control over the character of the terrain.
Offline BiGF00T

Junior Newbie





« Reply #11 - Posted 2011-11-28 20:19:34 »

I have generated some random terrain a few days ago and posted a blog entry about it including my (bad) code.

After I had read about Perlin Noise, I wanted to try to generate a map for a game I plan to do.

Because I thought it would be hard to fill the terrain below the line created by the perlin noise, I just used an image of terrain and shifted parts of its pixels downwards to create valleys. Probably not the best approach but it works.
Offline xinaesthetic

Senior Devvie


Medals: 1



« Reply #12 - Posted 2011-11-29 14:37:49 »

I have generated some random terrain a few days ago and posted a blog entry about it including my (bad) code.
FTFY.

p.s. your code looks pretty normal; good for you for being open and sharing it along with your thoughts.
Offline BiGF00T

Junior Newbie





« Reply #13 - Posted 2011-11-29 18:43:47 »

FTFY.
p.s. your code looks pretty normal; good for you for being open and sharing it along with your thoughts.
Thanks, still not used to forum tags.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (40 views)
2014-12-09 22:41:13

BurntPizza (75 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (113 views)
2014-11-26 15:22:04

toopeicgaming1999 (100 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
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!