Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Infinite level generation?  (Read 1476 times)
0 Members and 1 Guest are viewing this topic.
Online trollwarrior1
« Posted 2014-02-12 07:30:40 »

So I'm thinking of creating infinite map generation in my game.
The problem is, I cannot solve some problems Cheesy

Ok first of all I'm able to generate 2d array of tiles to my liking, and I could do that infinitely, probably. What I don't know how to do is generate objects on the map based on the seed. I can just use Random or something to randomly generate objects, but that isn't what I want. I want generated map to always be the same when same seed is specified.

Let me explain why I want this.
Here is how I'm thinking of doing infinite terrain.
* Generate infinite terrain for the first time. Keep track of the seed used to generate the terrain.
* Player changes certain tiles/entities in the world. Keep track of what the player has done.
* When saving, only save what the player changed in the world.
* After loading, generate terrain from same seed again, and apply changes that player previously made.

So this is really a "big" question, but the first thing I need to figure out is how to generate object/entities based on specific seed. I probably should use some kind of PRNG like XorShirt or something like that.

PS

Anybody knows how Minecraft stores/loads terrain?
Offline jonjava
« Reply #1 - Posted 2014-02-12 08:22:42 »

If you use the same seed you will get the same terrain. Why is this not working for you? Make sure to create and use a separate and specific Random object for terrain creation.

The map data should hold entity spawn points too - not only terrain data.

PS
In chunks.

Online trollwarrior1
« Reply #2 - Posted 2014-02-12 08:31:04 »

Ok look here for a moment. Lets say I have this PRNG.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
private static class xor {

      private long last;

      public xor(long seed) {
         last = seed;
      }
     
      public xor() {
         this(System.currentTimeMillis());
      }

      public int nextInt(int max) {
         long rand = last;

         rand ^= (rand << 21);
         rand ^= (rand >>> 35);
         rand ^= (rand << 4);

         last = rand;

         rand = (rand < 0 ? -rand : rand) % max;
         return (int) rand;
      }
     
      public int nextInt(int max, long seed) {
         long rand = seed;

         rand ^= (rand << 21);
         rand ^= (rand >>> 35);
         rand ^= (rand << 4);

         last = rand;

         rand = (rand < 0 ? -rand : rand) % max;
         return (int) rand;
      }
     

   }


Basically returns a value based on seed and caps it to "max".

Lets say I have tile "x = 241, y = 65"
How would I calculate seed value based on level seed(base seed which never changes) and x,y values?

I really suck at such math Cheesy Almost first time using it.


EDIT---------

Ow I think I know how.
Need to do this:
1  
long seed = 107759511739861197l ^ ((x<<5)+(y<<3) + 1);

that long is basically level seed or something that never changes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2014-02-12 08:53:25 »

Lets say I have tile "x = 241, y = 65"
How would I calculate seed value based on level seed(base seed which never changes) and x,y values?

... what!?

PS @Riven: is the "quoting" over 90% of the posts really a relevant issue?

Filler image:

Online trollwarrior1
« Reply #4 - Posted 2014-02-12 09:03:22 »

I hate the 90% thingy too..
I solved my problem already.. under EDIT----
Offline jonjava
« Reply #5 - Posted 2014-02-12 09:13:25 »

Well, good for you. Still makes no sense, though.

Offline Roquen
« Reply #6 - Posted 2014-02-12 10:03:05 »

This is exactly like noise.  Choose some size, take a predefined coordinate of that square (say lower-left), create a hashing value from the coordinate and that's your seed.
Offline JAW

Senior Member


Medals: 2



« Reply #7 - Posted 2014-02-12 17:41:04 »

Just to make this clear to anyone, the java.util.Random object has a constructer that accepts a seed and will produce the same values every time when using the same seed. It is exactly what you want and 100% reproduceable when running exactly the same procedure.

In cases where you have for some reason no reproduceable random generator, you might consider to genereate 100 or more random values and store them. Running through the same list of values over and over may be random enough for many cases and all you need to store is 100 or 200 or somewhat integers.

But generally, stick with the Random class and give it a seed.

-JAW
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2014-02-12 17:44:43 »

Filler image:

(sorry for off-topic)

Where the heck did you get those awesome sprites? Can I have the icon set? Could you share it? Can I use it for non-commercial stuff? Is it even yours?

Can I rip them myself? Grin

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline jonjava
« Reply #9 - Posted 2014-02-12 20:33:04 »

Filler image:

(sorry for off-topic)

Where the heck did you get those awesome sprites? Can I have the icon set? Could you share it? Can I use it for non-commercial stuff? Is it even yours?

Can I rip them myself? Grin

I have no idea. It's been on my HD for almost 2 years. They're not mine. It's a huge icon set called "bigset.png". Most likely ripped from multiple games.

~5MB in size - one huge sprite sheet [384x15096]
[link1] http://www28.speedyshare.com/32XEu/download/bigset.png
[link2] http://www.sendspace.com/file/i7doy2

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #10 - Posted 2014-02-13 16:05:28 »

Filler image:

(sorry for off-topic)

Where the heck did you get those awesome sprites? Can I have the icon set? Could you share it? Can I use it for non-commercial stuff? Is it even yours?

Can I rip them myself? Grin

I have no idea. It's been on my HD for almost 2 years. They're not mine. It's a huge icon set called "bigset.png". Most likely ripped from multiple games.

~5MB in size - one huge sprite sheet [384x15096]
[link1] http://www28.speedyshare.com/32XEu/download/bigset.png
[link2] http://www.sendspace.com/file/i7doy2


WHAAAT
THEEE

.. thank you Smiley

90% quote stuff ... :/

Filler image:

EDIT: Couldn't recognize everything but I saw some Guild Wars Skill images on the bottom. Seems like it might not be too safe to use it :/ thanks anyways. Might be helpful for prototyping! Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline saucymeatman
« Reply #11 - Posted 2014-02-26 02:22:54 »

Filler image:

(sorry for off-topic)

Where the heck did you get those awesome sprites? Can I have the icon set? Could you share it? Can I use it for non-commercial stuff? Is it even yours?

Can I rip them myself? Grin

I have no idea. It's been on my HD for almost 2 years. They're not mine. It's a huge icon set called "bigset.png". Most likely ripped from multiple games.

~5MB in size - one huge sprite sheet [384x15096]
[link1] http://www28.speedyshare.com/32XEu/download/bigset.png
[link2] http://www.sendspace.com/file/i7doy2

Thanks for these, thats alot of assets!
Definetly cool for placeholders, or whatever.
Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

atombrot (24 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (58 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!